All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] driver core: bus: Remove an impossible error handling path in bus_add_driver()
@ 2024-09-17  6:49 Zijun Hu
  2024-09-17  6:53 ` Zijun Hu
  0 siblings, 1 reply; 8+ messages in thread
From: Zijun Hu @ 2024-09-17  6:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: Zijun Hu, linux-kernel, Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

For the following function call chain:
API driver_register() -> bus_add_driver() -> driver_attach()

There is an error handling path for driver_attach() returning non-zero
or failure in bus_add_driver(), remove it with below reasons:

- It is impossible for driver_attach() to have failure in bus_add_driver()
  For int driver_attach(const struct device_driver *drv), the only factor
  which makes it failed is that bus_to_subsys(@drv->bus) is NULL, but
  the factor has been excluded by bus_add_driver() before calling it.

- driver_attach() is irrelevant with driver_register(), so the former's
  result should not also have an impact on the later.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
Changes in v2:
- Remove the error handling path instead of WARN_ON() it.
- Correct title and commit message
- Link to v1: https://lore.kernel.org/r/20240915-bus_add_driver_fix-v1-1-ce5cf1f66601@quicinc.com
---
 drivers/base/bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 657c93c38b0d..54ff92aece92 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -674,7 +674,8 @@ int bus_add_driver(struct device_driver *drv)
 	if (sp->drivers_autoprobe) {
 		error = driver_attach(drv);
 		if (error)
-			goto out_del_list;
+			pr_warn("%s: failed to attach driver '%s' to bus '%s'\n",
+				__func__, drv->name, sp->bus->name);
 	}
 	error = module_add_driver(drv->owner, drv);
 	if (error) {
@@ -708,7 +709,6 @@ int bus_add_driver(struct device_driver *drv)
 
 out_detach:
 	driver_detach(drv);
-out_del_list:
 	klist_del(&priv->knode_bus);
 out_unregister:
 	kobject_put(&priv->kobj);

---
base-commit: 6a36d828bdef0e02b1e6c12e2160f5b83be6aab5
change-id: 20240915-bus_add_driver_fix-f54841e6a69a

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-10-13 16:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-17  6:49 [PATCH v2] driver core: bus: Remove an impossible error handling path in bus_add_driver() Zijun Hu
2024-09-17  6:53 ` Zijun Hu
2024-10-13 15:02   ` Greg Kroah-Hartman
2024-10-13 15:46     ` Zijun Hu
2024-10-13 16:00       ` Greg Kroah-Hartman
2024-10-13 16:13         ` Zijun Hu
2024-10-13 16:24           ` Greg Kroah-Hartman
2024-10-13 16:35             ` Zijun Hu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.