mbox series

[0/4] i2c: devm_pinctrl_get() usage fixes

Message ID 20230816200410.62131-1-yann@sionneau.net
Headers show
Series i2c: devm_pinctrl_get() usage fixes | expand

Message

Yann Sionneau Aug. 16, 2023, 8:04 p.m. UTC
Most of the patches just remove the check for NULL for devm_pinctrl_get()
return value since it cannot return NULL.

One patch also sets back rinfo->pinctrl to NULL when devm_pinctrl_get()
returns an error instead of a valid pointer and the driver does not bail
out.
This last change prevents core i2c code to dereference invalid pointer
because it checks for rinfo->pinctrl validity with "if (rinfo->pinctrl)"
before dereferencing it.

Yann Sionneau (4):
  i2c: mv64xxx: devm_pinctrl_get() cannot return NULL
  i2c: at91-master: devm_pinctrl_get() cannot return NULL
  i2c: i2c-cadence: Reset pinctrl to NULL in case devm_pinctrl_get()
    fails
  i2c: imx: devm_pinctrl_get() cannot return NULL

 drivers/i2c/busses/i2c-at91-master.c | 2 +-
 drivers/i2c/busses/i2c-cadence.c     | 1 +
 drivers/i2c/busses/i2c-imx.c         | 2 +-
 drivers/i2c/busses/i2c-mv64xxx.c     | 2 --
 4 files changed, 3 insertions(+), 4 deletions(-)

Comments

Oleksij Rempel Aug. 17, 2023, 4:46 a.m. UTC | #1
On Wed, Aug 16, 2023 at 10:04:10PM +0200, Yann Sionneau wrote:
> Remove unnecessary check against NULL for devm_pinctrl_get() return value.
> 
> Signed-off-by: Yann Sionneau <yann@sionneau.net>
> ---
>  drivers/i2c/busses/i2c-imx.c | 2 +-

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!

>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 65128a73e8a3..502276e8ded5 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1389,7 +1389,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
>  	struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
>  
>  	i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> -	if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
> +	if (IS_ERR(i2c_imx->pinctrl)) {
>  		dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
>  		return PTR_ERR(i2c_imx->pinctrl);
>  	}
> -- 
> 2.34.1
> 
>