mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe()
@ 2026-02-02  2:40 Chen Ni
  2026-02-02 11:52 ` Dave Stevenson
  2026-02-04  0:56 ` Jai Luthra
  0 siblings, 2 replies; 4+ messages in thread
From: Chen Ni @ 2026-02-02  2:40 UTC (permalink / raw)
  To: sakari.ailus, dave.stevenson, mchehab; +Cc: linux-media, linux-kernel, Chen Ni

The devm_gpiod_get_optional() function may return an error pointer
(ERR_PTR) in case of a genuine failure during GPIO acquisition,
not just NULL which indicates the legitimate absence of an optional
GPIO.

Add an IS_ERR() check after the function call to catch such errors and
propagate them to the probe function, ensuring the driver fails to load
safely rather than proceeding with an invalid pointer.

Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 drivers/media/i2c/imx219.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index fee63bc106d9..7da02ce5da15 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1218,6 +1218,9 @@ static int imx219_probe(struct i2c_client *client)
 	/* Request optional enable pin */
 	imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 						     GPIOD_OUT_HIGH);
+	if (IS_ERR(imx219->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(imx219->reset_gpio),
+				     "failed to get reset gpio\n");
 
 	/*
 	 * The sensor must be powered for imx219_identify_module()
-- 
2.25.1


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

* Re: [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe()
  2026-02-02  2:40 [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe() Chen Ni
@ 2026-02-02 11:52 ` Dave Stevenson
  2026-02-04  0:56 ` Jai Luthra
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Stevenson @ 2026-02-02 11:52 UTC (permalink / raw)
  To: Chen Ni; +Cc: sakari.ailus, mchehab, linux-media, linux-kernel

On Mon, 2 Feb 2026 at 02:41, Chen Ni <nichen@iscas.ac.cn> wrote:
>
> The devm_gpiod_get_optional() function may return an error pointer
> (ERR_PTR) in case of a genuine failure during GPIO acquisition,
> not just NULL which indicates the legitimate absence of an optional
> GPIO.
>
> Add an IS_ERR() check after the function call to catch such errors and
> propagate them to the probe function, ensuring the driver fails to load
> safely rather than proceeding with an invalid pointer.
>
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>

Thanks for the patch

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

(Apologies to those directly on the cc for the earlier HTML version of
this R-b. Google appears to have updated the composition settings for
me, and I hadn't noticed)

> ---
>  drivers/media/i2c/imx219.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index fee63bc106d9..7da02ce5da15 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -1218,6 +1218,9 @@ static int imx219_probe(struct i2c_client *client)
>         /* Request optional enable pin */
>         imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset",
>                                                      GPIOD_OUT_HIGH);
> +       if (IS_ERR(imx219->reset_gpio))
> +               return dev_err_probe(dev, PTR_ERR(imx219->reset_gpio),
> +                                    "failed to get reset gpio\n");
>
>         /*
>          * The sensor must be powered for imx219_identify_module()
> --
> 2.25.1
>

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

* Re: [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe()
  2026-02-02  2:40 [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe() Chen Ni
  2026-02-02 11:52 ` Dave Stevenson
@ 2026-02-04  0:56 ` Jai Luthra
  2026-02-04  2:48   ` [PATCH v2] " Chen Ni
  1 sibling, 1 reply; 4+ messages in thread
From: Jai Luthra @ 2026-02-04  0:56 UTC (permalink / raw)
  To: Chen Ni, dave.stevenson, mchehab, sakari.ailus
  Cc: linux-media, linux-kernel, Chen Ni, stable

Quoting Chen Ni (2026-02-02 08:10:24)
> The devm_gpiod_get_optional() function may return an error pointer
> (ERR_PTR) in case of a genuine failure during GPIO acquisition,
> not just NULL which indicates the legitimate absence of an optional
> GPIO.
> 
> Add an IS_ERR() check after the function call to catch such errors and
> propagate them to the probe function, ensuring the driver fails to load
> safely rather than proceeding with an invalid pointer.

Good catch, maybe a fixes tag is appropriate so this gets backported to
stable kernels.

Fixes: 1283b3b8f82b ("media: i2c: Add driver for Sony IMX219 sensor")

with that,

Reviewed-by: Jai Luthra <jai.luthra@ideasonboard.com>

> 
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>  drivers/media/i2c/imx219.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index fee63bc106d9..7da02ce5da15 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -1218,6 +1218,9 @@ static int imx219_probe(struct i2c_client *client)
>         /* Request optional enable pin */
>         imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset",
>                                                      GPIOD_OUT_HIGH);
> +       if (IS_ERR(imx219->reset_gpio))
> +               return dev_err_probe(dev, PTR_ERR(imx219->reset_gpio),
> +                                    "failed to get reset gpio\n");
>  
>         /*
>          * The sensor must be powered for imx219_identify_module()
> -- 
> 2.25.1
> 
>

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

* [PATCH v2] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe()
  2026-02-04  0:56 ` Jai Luthra
@ 2026-02-04  2:48   ` Chen Ni
  0 siblings, 0 replies; 4+ messages in thread
From: Chen Ni @ 2026-02-04  2:48 UTC (permalink / raw)
  To: dave.stevenson, sakari.ailus, mchehab, andrey.konovalov, jai.luthra
  Cc: linux-media, linux-kernel, Chen Ni

The devm_gpiod_get_optional() function may return an error pointer
(ERR_PTR) in case of a genuine failure during GPIO acquisition,
not just NULL which indicates the legitimate absence of an optional
GPIO.

Add an IS_ERR() check after the function call to catch such errors and
propagate them to the probe function, ensuring the driver fails to load
safely rather than proceeding with an invalid pointer.

Fixes: 1283b3b8f82b ("media: i2c: Add driver for Sony IMX219 sensor")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jai Luthra <jai.luthra@ideasonboard.com>
---
Changes in v2:
- Add Fixes tag.
---
 drivers/media/i2c/imx219.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index fee63bc106d9..7da02ce5da15 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1218,6 +1218,9 @@ static int imx219_probe(struct i2c_client *client)
 	/* Request optional enable pin */
 	imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 						     GPIOD_OUT_HIGH);
+	if (IS_ERR(imx219->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(imx219->reset_gpio),
+				     "failed to get reset gpio\n");
 
 	/*
 	 * The sensor must be powered for imx219_identify_module()
-- 
2.25.1


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

end of thread, other threads:[~2026-02-04  2:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-02  2:40 [PATCH] media: i2c: imx219: Check return value of devm_gpiod_get_optional() in imx219_probe() Chen Ni
2026-02-02 11:52 ` Dave Stevenson
2026-02-04  0:56 ` Jai Luthra
2026-02-04  2:48   ` [PATCH v2] " Chen Ni

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

all inboxes | Powered by JetHome®