[PATCH v4 1/3] driver-core: return EINVAL error instead of BUG_ON()
From: Florian Schmaus
Date: Wed May 16 2018 - 07:33:23 EST
I triggerd the BUG_ON() in driver_register() when booting a domU Xen
domain. Since there was no contextual information logged, I needed to
attach kgdb to determine the culprit (the wmi-bmof driver in my
case). The BUG_ON() was added in commit f48f3febb2cb ("driver-core: do
not register a driver with bus_type not registered").
Instead of running into a BUG_ON() we print an error message
identifying the, likely faulty, driver but continue booting.
Signed-off-by: Florian Schmaus <flo@xxxxxxxxxxxx>
---
Notes:
- Also print out the bus name
- Use pr_err() instead of printk()
drivers/base/driver.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index ba912558a510..203fa731e3ee 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -148,7 +148,12 @@ int driver_register(struct device_driver *drv)
int ret;
struct device_driver *other;
- BUG_ON(!drv->bus->p);
+ if (!drv->bus->p) {
+ pr_err("Driver '%s' was unable to register with bus_type '%s'"
+ " because it was not initialized.\n",
+ drv->name, drv->bus->name);
+ return -EINVAL;
+ }
if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
--
2.16.1