git: d87fad36330b - main - linuxkpi: Acquire giant when adding/removing i2c adapters

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 15 Jun 2022 11:38:44 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=d87fad36330b6faf657e7ee8faaa52feeaaff68a

commit d87fad36330b6faf657e7ee8faaa52feeaaff68a
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-06-14 11:23:26 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-06-15 11:37:43 +0000

    linuxkpi: Acquire giant when adding/removing i2c adapters
    
    We need Giant as we run in a taskqueue_thread via linux_work.
    This fix detaching amdgpu and i915kms.
    
    Reviewed by:    bz, hselasky, imp
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D35478
---
 sys/compat/linuxkpi/common/src/linux_i2c.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_i2c.c b/sys/compat/linuxkpi/common/src/linux_i2c.c
index c2c4977eb9ba..bdf381f8a032 100644
--- a/sys/compat/linuxkpi/common/src/linux_i2c.c
+++ b/sys/compat/linuxkpi/common/src/linux_i2c.c
@@ -221,7 +221,9 @@ lkpi_i2c_add_adapter(struct i2c_adapter *adapter)
 		return (ENXIO);
 	}
 
+	bus_topo_lock();
 	error = bus_generic_attach(adapter->dev.parent->bsddev);
+	bus_topo_unlock();
 	if (error) {
 		device_printf(adapter->dev.parent->bsddev,
 		  "failed to attach child: error %d\n", error);
@@ -249,7 +251,9 @@ lkpi_i2c_del_adapter(struct i2c_adapter *adapter)
 	while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iic", unit++)) != NULL) {
 
 		if (adapter == LKPI_IIC_GET_ADAPTER(child)) {
+			bus_topo_lock();
 			device_delete_child(adapter->dev.parent->bsddev, child);
+			bus_topo_unlock();
 			rv = 0;
 			goto out;
 		}
@@ -259,7 +263,9 @@ lkpi_i2c_del_adapter(struct i2c_adapter *adapter)
 	while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iicbb", unit++)) != NULL) {
 
 		if (adapter == LKPI_IIC_GET_ADAPTER(child)) {
+			bus_topo_lock();
 			device_delete_child(adapter->dev.parent->bsddev, child);
+			bus_topo_unlock();
 			rv = 0;
 			goto out;
 		}