Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bus_remove_device: be more careful about incomplete initialization

Prevent bus_remove_device() from crashing if dev->knode_bus has not been
initialized before it's called.

This can happen if the device_add() ended up breaking out early due to
an error, for example.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Rafael J. Wysocki and committed by
Linus Torvalds
29591b92 08119e89

+2 -1
+2 -1
drivers/base/bus.c
··· 530 530 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 531 531 dev->bus_id); 532 532 device_remove_attrs(dev->bus, dev); 533 - klist_del(&dev->knode_bus); 533 + if (klist_node_attached(&dev->knode_bus)) 534 + klist_del(&dev->knode_bus); 534 535 535 536 pr_debug("bus: '%s': remove device %s\n", 536 537 dev->bus->name, dev->bus_id);