mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
driver core: reject devices with unregistered buses
commit36f35b8df6upstream. Trying to register a device on a bus which has not yet been registered used to trigger a NULL-pointer dereference, but since the const bus structure rework registration instead succeeds without the device being added to the bus. This specifically means that the device will never bind to a driver and that the bus sysfs attributes are not created (i.e. as if the device had no bus). Reject devices with unregistered buses to catch any callers that get the ordering wrong and to handle bus registration failures more gracefully. Fixes:5221b82d46("driver core: bus: bus_add/probe/remove_device() cleanups") Cc: stable@vger.kernel.org # 6.3 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://patch.msgid.link/20260430091718.230228-1-johan@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b5fa9e32fb
commit
000e8f55fb
+9
-2
@@ -503,10 +503,10 @@ static const struct attribute_group driver_override_dev_group = {
|
||||
*/
|
||||
int bus_add_device(struct device *dev)
|
||||
{
|
||||
struct subsys_private *sp = bus_to_subsys(dev->bus);
|
||||
struct subsys_private *sp;
|
||||
int error;
|
||||
|
||||
if (!sp) {
|
||||
if (!dev->bus) {
|
||||
/*
|
||||
* This is a normal operation for many devices that do not
|
||||
* have a bus assigned to them, just say that all went
|
||||
@@ -515,6 +515,13 @@ int bus_add_device(struct device *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp = bus_to_subsys(dev->bus);
|
||||
if (!sp) {
|
||||
pr_err("%s: cannot add device '%s' to unregistered bus '%s'\n",
|
||||
__func__, dev_name(dev), dev->bus->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reference in sp is now incremented and will be dropped when
|
||||
* the device is removed from the bus
|
||||
|
||||
Reference in New Issue
Block a user