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

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Sep 16 02:38:48 PDT 2025


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?

Thanks,
Ahmad

> 
> Fixes: Fixes: 20d87123a6 ("treewide: replace dev_get_drvdata with device_get_match_data")
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/mtd/nand/raw/nand_mxs.c | 2 +-
>  drivers/net/fec_imx.h           | 2 +-
>  drivers/net/fsl-fman.c          | 2 +-
>  drivers/regulator/fan53555.c    | 2 +-
>  include/linux/mfd/axp20x.h      | 2 +-
>  include/mfd/bd71837.h           | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_mxs.c b/drivers/mtd/nand/raw/nand_mxs.c
> index 02f8546b87..4293f4e0e0 100644
> --- a/drivers/mtd/nand/raw/nand_mxs.c
> +++ 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,
>  };
>  
> diff --git a/drivers/net/fec_imx.h b/drivers/net/fec_imx.h
> index 1aaff87fdd..33b8db2745 100644
> --- a/drivers/net/fec_imx.h
> +++ b/drivers/net/fec_imx.h
> @@ -114,7 +114,7 @@ struct buffer_descriptor {
>  };
>  
>  enum fec_type {
> -	FEC_TYPE_IMX27,
> +	FEC_TYPE_IMX27 = 1,
>  	FEC_TYPE_IMX28,
>  	FEC_TYPE_IMX6,
>  };
> diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
> index bde054d751..ac716c7468 100644
> --- a/drivers/net/fsl-fman.c
> +++ b/drivers/net/fsl-fman.c
> @@ -123,7 +123,7 @@ struct fsl_fman_mdio {
>  };
>  
>  enum fman_port_type {
> -	FMAN_PORT_TYPE_RX = 0,	/* RX Port */
> +	FMAN_PORT_TYPE_RX = 1,	/* RX Port */
>  	FMAN_PORT_TYPE_TX,	/* TX Port */
>  };
>  
> diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
> index 2dcc6f5394..7477543915 100644
> --- a/drivers/regulator/fan53555.c
> +++ b/drivers/regulator/fan53555.c
> @@ -44,7 +44,7 @@ enum {
>  };
>  
>  enum fan53555_vendor {
> -	FAN53526_VENDOR_FAIRCHILD = 0,
> +	FAN53526_VENDOR_FAIRCHILD = 1,
>  	FAN53555_VENDOR_FAIRCHILD,
>  	FAN53555_VENDOR_ROCKCHIP,	/* RK8600, RK8601 */
>  	RK8602_VENDOR_ROCKCHIP,		/* RK8602, RK8603 */
> diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
> index 93d303c459..0ba4568faf 100644
> --- a/include/linux/mfd/axp20x.h
> +++ b/include/linux/mfd/axp20x.h
> @@ -11,7 +11,7 @@
>  #include <poweroff.h>
>  
>  enum axp20x_variants {
> -	AXP152_ID = 0,
> +	AXP152_ID = 1,
>  	AXP202_ID,
>  	AXP209_ID,
>  	AXP221_ID,
> diff --git a/include/mfd/bd71837.h b/include/mfd/bd71837.h
> index 4e285a647a..ab4cc57c88 100644
> --- a/include/mfd/bd71837.h
> +++ b/include/mfd/bd71837.h
> @@ -7,7 +7,7 @@
>  #define BD718XX_REGULATOR_DRIVER "bd718x7_regulator"
>  
>  enum {
> -	ROHM_CHIP_TYPE_BD71837 = 0,
> +	ROHM_CHIP_TYPE_BD71837 = 1,
>  	ROHM_CHIP_TYPE_BD71847,
>  	ROHM_CHIP_TYPE_BD70528,
>  	ROHM_CHIP_TYPE_AMOUNT

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