Skip to content

Commit e8b812b

Browse files
geertugregkh
authored andcommitted
driver core: bus: Handle early calls to bus_to_subsys()
When calling soc_device_match() from early_initcall(), bus_kset is still NULL, causing a crash: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028 ... Call trace: __lock_acquire+0x530/0x20f0 lock_acquire.part.0+0xc8/0x210 lock_acquire+0x64/0x80 _raw_spin_lock+0x4c/0x60 bus_to_subsys+0x24/0xac bus_for_each_dev+0x30/0xcc soc_device_match+0x4c/0xe0 r8a7795_sysc_init+0x18/0x60 rcar_sysc_pd_init+0xb0/0x33c do_one_initcall+0x128/0x2bc Before, bus_for_each_dev() handled this gracefully by checking that the back-pointer to the private structure was valid. Fix this by adding a NULL check for bus_kset to bus_to_subsys(). Fixes: 83b9148 ("driver core: bus: bus iterator cleanups") Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/0a92979f6e790737544638e8a4c19b0564e660a2.1676983596.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a93e884 commit e8b812b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/base/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static struct subsys_private *bus_to_subsys(const struct bus_type *bus)
6262
struct subsys_private *sp = NULL;
6363
struct kobject *kobj;
6464

65-
if (!bus)
65+
if (!bus || !bus_kset)
6666
return NULL;
6767

6868
spin_lock(&bus_kset->list_lock);

0 commit comments

Comments
 (0)