From e8b812b3e515742a4faaf2e4722bdc5755b98f56 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 21 Feb 2023 13:53:51 +0100 Subject: 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: 83b9148df2c95e23 ("driver core: bus: bus iterator cleanups") Signed-off-by: Geert Uytterhoeven Link: https://lore.kernel.org/r/0a92979f6e790737544638e8a4c19b0564e660a2.1676983596.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index cfe8615d5106..dd4b82d7510f 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -62,7 +62,7 @@ static struct subsys_private *bus_to_subsys(const struct bus_type *bus) struct subsys_private *sp = NULL; struct kobject *kobj; - if (!bus) + if (!bus || !bus_kset) return NULL; spin_lock(&bus_kset->list_lock); -- cgit From 6309872413f14f3d58c13ae4dc85b1a7004b4193 Mon Sep 17 00:00:00 2001 From: Saravana Kannan Date: Fri, 24 Feb 2023 22:41:47 -0800 Subject: driver core: fw_devlink: Avoid spurious error message fw_devlink can sometimes try to create a device link with the consumer and supplier as the same device. These attempts will fail (correctly), but are harmless. So, avoid printing an error for these cases. Also, add more detail to the error message. Fixes: 3fb16866b51d ("driver core: fw_devlink: Make cycle detection more robust") Reported-by: Vladimir Oltean Reported-by: Dmitry Baryshkov Signed-off-by: Saravana Kannan Link: https://lore.kernel.org/r/20230225064148.274376-1-saravanak@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index e54a10b5dbd7..863eb42359db 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2046,9 +2046,9 @@ static int fw_devlink_create_devlink(struct device *con, goto out; } - if (!device_link_add(con, sup_dev, flags)) { - dev_err(con, "Failed to create device link with %s\n", - dev_name(sup_dev)); + if (con != sup_dev && !device_link_add(con, sup_dev, flags)) { + dev_err(con, "Failed to create device link (0x%x) with %s\n", + flags, dev_name(sup_dev)); ret = -EINVAL; } -- cgit From 0c058fb94ae0e2a68639f4569de1c3abf5df7ad7 Mon Sep 17 00:00:00 2001 From: Saravana Kannan Date: Fri, 24 Feb 2023 22:54:42 -0800 Subject: driver core: fw_devlink: Print full path and name of fwnode Some of the log messages were printing just the fwnode name. While it's short, it's not always uniquely identifiable in system. So print the full path and name to make debugging easier. Signed-off-by: Saravana Kannan Link: https://lore.kernel.org/r/20230225065443.278284-1-saravanak@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 863eb42359db..6878dfcbf0d6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -98,7 +98,7 @@ static int __fwnode_link_add(struct fwnode_handle *con, list_add(&link->s_hook, &sup->consumers); list_add(&link->c_hook, &con->suppliers); - pr_debug("%pfwP Linked as a fwnode consumer to %pfwP\n", + pr_debug("%pfwf Linked as a fwnode consumer to %pfwf\n", con, sup); return 0; @@ -122,7 +122,7 @@ int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup) */ static void __fwnode_link_del(struct fwnode_link *link) { - pr_debug("%pfwP Dropping the fwnode link to %pfwP\n", + pr_debug("%pfwf Dropping the fwnode link to %pfwf\n", link->consumer, link->supplier); list_del(&link->s_hook); list_del(&link->c_hook); @@ -1062,7 +1062,7 @@ int device_links_check_suppliers(struct device *dev) if (!dev_is_best_effort(dev)) { fwnode_ret = -EPROBE_DEFER; dev_err_probe(dev, -EPROBE_DEFER, - "wait for supplier %pfwP\n", sup_fw); + "wait for supplier %pfwf\n", sup_fw); } else { fwnode_ret = -EAGAIN; } -- cgit