[PATCH] drivers: treewide: Do not use NULL as driver_data

Sascha Hauer s.hauer at pengutronix.de
Wed Sep 17 07:02:33 PDT 2025


On Tue, Sep 16, 2025 at 11:38:48AM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 9/16/25 11:32 AM, Sascha Hauer wrote:
> > Several drivers in the tree use an enum for the chip type casted to int
> > as driver_data. This comes with the problem that device_get_match_data()
> > returns NULL for these devices and a potential error check bails out
> > then.
> > 
> > This patch changes the enums used by the drivers to start from 1 instead
> > of 0 so that the return value of device_get_match_data() can safely
> > checked for being NULL.
> > 
> > Most drivers do not check the return value anyway, but fec_imx.c does
> > which causes the driver to no longer work on i.MX27. This issue is fixed
> > here.
> 
> If they don't check the return value, why bother changing it and risk a
> regression?

To not give others bad examples.

> > +++ b/drivers/mtd/nand/raw/nand_mxs.c
> > @@ -38,7 +38,7 @@
> >  #include "internals.h"
> >  
> >  enum gpmi_type {
> > -	GPMI_MXS,
> > +	GPMI_MXS = 1,
> >  	GPMI_IMX6,
> >  };

Anyway, this indeed introduces a regression. We have mxs_add_nand()
which instantiates a "mxs_nand" device without driver data, so
device_get_match_data() will return 0 aka GPMI_MXS which happens to
be the right thing here.

Sascha

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



More information about the barebox mailing list