summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-02-10 19:07:50 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-02-12 08:32:01 +0100
commit671a7d5df1c1bae1fca1cebf5b72e2a27b352c70 (patch)
tree75eb6c5d78b16a8b561dc9e9dac5e2fe1cae3a6e /drivers
parent37f468f474351b81603f058103945edce206e77a (diff)
downloadbarebox-671a7d5df1c1bae1fca1cebf5b72e2a27b352c70.tar.gz
barebox-671a7d5df1c1bae1fca1cebf5b72e2a27b352c70.tar.xz
driver: bail out, don't crash, if drv->name is not set
Currently, we expect each driver to have a name. If a driver doesn't, we run into a NULL pointer dereference. Make this error scenario more pleasant by checking if a name is set and failing otherwise. The only in-tree driver affected by this is drivers/watchdog/dw_wdt.c, which will be fixed in the follow-up commit. Affected drivers can be determined with following pipeline, which should return all driver_d structure instantiations that don't contain a name: ack --A 4 'struct driver_d.*' | perl -pe 's/^--$/\n/' | \ perl -000 -ne 'print if /=.*\{.*\}/s && !/name/s' With this change, these drivers should now give a more pleasant message: ERROR: initcall dw_wdt_driver_register+0x1/0xc failed: Invalid argument Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/driver.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eec2a2d8a2..116ccb2586 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -308,6 +308,9 @@ int register_driver(struct driver_d *drv)
{
struct device_d *dev = NULL;
+ if (!drv->name)
+ return -EINVAL;
+
debug("register_driver: %s\n", drv->name);
BUG_ON(!drv->bus);