From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set
Date: Mon, 10 Feb 2020 19:07:50 +0100 [thread overview]
Message-ID: <20200210180751.31108-1-a.fatoum@pengutronix.de> (raw)
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>
---
drivers/base/driver.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eec2a2d8a2a5..116ccb25864b 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);
--
2.25.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2020-02-10 18:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 18:07 Ahmad Fatoum [this message]
2020-02-10 18:07 ` [PATCH 2/2] watchdog: dw_wdt: populate driver_d.name Ahmad Fatoum
2020-02-12 7:32 ` [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200210180751.31108-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox