mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set
@ 2020-02-10 18:07 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2020-02-10 18:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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

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

* [PATCH 2/2] watchdog: dw_wdt: populate driver_d.name
  2020-02-10 18:07 [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set Ahmad Fatoum
@ 2020-02-10 18:07 ` Ahmad Fatoum
  2020-02-12  7:32 ` [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2020-02-10 18:07 UTC (permalink / raw)
  To: barebox; +Cc: Steffen Trumtrar, Ahmad Fatoum

Apparently, somewhere between v2017.01.0 and v2020.01.0, barebox became
dependent on drivers having a name as having this driver enabled in
v2020.01.0 has barebox crash due to a null pointer dereference in the
device_match's second strcmp.

A previous commit introduced a palatable warning for this case.
Now in order to be able to use the driver again, give it a name.

Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/watchdog/dw_wdt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index a029da2b2f4a..cb0d17e3610b 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -189,6 +189,7 @@ static struct of_device_id dw_wdt_of_match[] = {
 };
 
 static struct driver_d dw_wdt_driver = {
+	.name		= "dw-wdt",
 	.probe		= dw_wdt_drv_probe,
 	.of_compatible	= DRV_OF_COMPAT(dw_wdt_of_match),
 };
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set
  2020-02-10 18:07 [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set Ahmad Fatoum
  2020-02-10 18:07 ` [PATCH 2/2] watchdog: dw_wdt: populate driver_d.name Ahmad Fatoum
@ 2020-02-12  7:32 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-02-12  7:32 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Feb 10, 2020 at 07:07:50PM +0100, Ahmad Fatoum wrote:
> 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(+)

Applied, thanks

Sascha

> 
> 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
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-02-12  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 18:07 [PATCH 1/2] driver: bail out, don't crash, if drv->name is not set Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox