driver core: take parent lock on deferred probe

USB interfaces should be probed with the parent USB device lock held,
but this is not honoured when probe is deferred.

Add a new bus_probe_device_deferred() helper to handle deferred probe
where the parent device lock is not held.

Fixes: d1c3414c2a ("drivercore: Add driver probe deferral mechanism")
Reported-by: Mario Peter <mario.peter@leica-geosystems.com>
Link: https://lore.kernel.org/20261007131514.1260696-1-mario.peter@leica-geosystems.com
Cc: stable@vger.kernel.org	# 3.4
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20261014133109.1392265-3-johan@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Johan Hovold 2026-10-14 15:31:08 +02:00 committed by Danilo Krummrich
parent 0f554506a3
commit 4059f8986c
3 changed files with 26 additions and 10 deletions

View File

@ -154,6 +154,7 @@ struct kobject *virtual_device_parent(void);
int bus_add_device(struct device *dev);
void bus_probe_device(struct device *dev);
void bus_probe_device_deferred(struct device *dev);
void bus_remove_device(struct device *dev);
void bus_notify(struct device *dev, enum bus_notifier_event value);
bool bus_is_registered(const struct bus_type *bus);

View File

@ -603,13 +603,7 @@ int bus_add_device(struct device *dev)
return error;
}
/**
* bus_probe_device - probe drivers for a new device
* @dev: device to probe
*
* - Automatically probe for a driver if the bus allows it.
*/
void bus_probe_device(struct device *dev)
static void __bus_probe_device(struct device *dev)
{
struct subsys_private *sp = bus_to_subsys(dev->bus);
struct subsys_interface *sif;
@ -627,6 +621,26 @@ void bus_probe_device(struct device *dev)
subsys_put(sp);
}
/**
* bus_probe_device - probe drivers for a new device
* @dev: device to probe
*
* - Automatically probe for a driver if the bus allows it.
*/
void bus_probe_device(struct device *dev)
{
__bus_probe_device(dev);
}
void bus_probe_device_deferred(struct device *dev)
{
if (dev->type && dev->type->need_parent_lock)
device_lock(dev->parent);
__bus_probe_device(dev);
if (dev->type && dev->type->need_parent_lock)
device_unlock(dev->parent);
}
/**
* bus_remove_device - remove device from bus
* @dev: device to be removed

View File

@ -86,8 +86,9 @@ static void deferred_probe_work_func(struct work_struct *work)
/*
* This block processes every device in the deferred 'active' list.
* Each device is removed from the active list and passed to
* bus_probe_device() to re-attempt the probe. The loop continues
* until every device in the active list is removed and retried.
* bus_probe_device_deferred() to re-attempt the probe. The loop
* continues until every device in the active list is removed and
* retried.
*
* Note: Once the device is removed from the list and the mutex is
* released, it is possible for the device get freed by another thread
@ -121,7 +122,7 @@ static void deferred_probe_work_func(struct work_struct *work)
device_pm_move_to_tail(dev);
dev_dbg(dev, "Retrying from deferred list\n");
bus_probe_device(dev);
bus_probe_device_deferred(dev);
mutex_lock(&deferred_probe_mutex);
put_device(dev);