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>
1 parent 37f468f commit 671a7d5df1c1bae1fca1cebf5b72e2a27b352c70
@Ahmad Fatoum Ahmad Fatoum authored on 10 Feb 2020
Sascha Hauer committed on 12 Feb 2020
Showing 1 changed file
View
drivers/base/driver.c