From d621ee6564d749847029b0f0e1b8a7e46f6d7831 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 14 Jun 2022 00:34:46 -0400 Subject: [PATCH] freebsd_network: Move up Giant ownership during attach. device_attach can be recursed for MIIbus drivers, so avoid the complexity and lock Giant from init_drivers() instead. --- src/libs/compat/freebsd_network/device.c | 4 ---- src/libs/compat/freebsd_network/driver.c | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/compat/freebsd_network/device.c b/src/libs/compat/freebsd_network/device.c index 05adbf5505..7504d35cc0 100644 --- a/src/libs/compat/freebsd_network/device.c +++ b/src/libs/compat/freebsd_network/device.c @@ -481,9 +481,6 @@ device_attach(device_t device) || device->methods.attach == NULL) return B_ERROR; - // Always hold the giant lock during attach. - mtx_lock(&Giant); - result = device->methods.attach(device); if (result == 0) @@ -492,7 +489,6 @@ device_attach(device_t device) if (result == 0 && HAIKU_DRIVER_REQUIRES(FBSD_WLAN_FEATURE)) result = start_wlan(device); - mtx_unlock(&Giant); return result; } diff --git a/src/libs/compat/freebsd_network/driver.c b/src/libs/compat/freebsd_network/driver.c index 4eada982ff..762e392e9a 100644 --- a/src/libs/compat/freebsd_network/driver.c +++ b/src/libs/compat/freebsd_network/driver.c @@ -310,6 +310,9 @@ _fbsd_init_drivers() if (status < B_OK) goto err6; + // Always hold the giant lock during attach. + mtx_lock(&Giant); + for (int p = 0; sProbedDevices[p].bus != BUS_INVALID; p++) { device_t root, device = NULL; status = init_root_device(&root, sProbedDevices[p].bus); @@ -341,6 +344,8 @@ _fbsd_init_drivers() device_delete_child(NULL, root); } + mtx_unlock(&Giant); + if (gDeviceCount > 0) return B_OK;