public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe()
@ 2026-01-30  4:18 Chen Ni
  2026-01-31  6:24 ` Markus Elfring
  2026-02-06  6:39 ` Krzysztof Hałasa
  0 siblings, 2 replies; 3+ messages in thread
From: Chen Ni @ 2026-01-30  4:18 UTC (permalink / raw)
  To: khalasa, sakari.ailus, 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/ar0521.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/ar0521.c b/drivers/media/i2c/ar0521.c
index f156058500e3..ed324c2d87aa 100644
--- a/drivers/media/i2c/ar0521.c
+++ b/drivers/media/i2c/ar0521.c
@@ -1094,6 +1094,9 @@ static int ar0521_probe(struct i2c_client *client)
 	/* Request optional reset pin (usually active low) and assert it */
 	sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 						     GPIOD_OUT_HIGH);
+	if (IS_ERR(sensor->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(sensor->reset_gpio),
+				     "failed to get reset gpio\n");
 
 	v4l2_i2c_subdev_init(&sensor->sd, client, &ar0521_subdev_ops);
 
-- 
2.25.1


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

* Re: [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe()
  2026-01-30  4:18 [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe() Chen Ni
@ 2026-01-31  6:24 ` Markus Elfring
  2026-02-06  6:39 ` Krzysztof Hałasa
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-01-31  6:24 UTC (permalink / raw)
  To: Chen Ni, linux-media, Krzysztof Hałasa,
	Mauro Carvalho Chehab, Sakari Ailus
  Cc: LKML> 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.

* Were any source code analysis tools involved here?

* Did anything hinder to add any tags (like “Fixes” and “Cc”) accordingly?


Regards,
Markus

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

* Re: [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe()
  2026-01-30  4:18 [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe() Chen Ni
  2026-01-31  6:24 ` Markus Elfring
@ 2026-02-06  6:39 ` Krzysztof Hałasa
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Hałasa @ 2026-02-06  6:39 UTC (permalink / raw)
  To: Chen Ni; +Cc: sakari.ailus, mchehab, linux-media, linux-kernel

Hi Chen,

Chen Ni <nichen@iscas.ac.cn> writes:

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

Well, it seems only right. Though I would prefer all-caps "GPIO" in
kernel messages. Either way,

Acked-by: Krzysztof Hałasa <khalasa@piap.pl>

> --- a/drivers/media/i2c/ar0521.c
> +++ b/drivers/media/i2c/ar0521.c
> @@ -1094,6 +1094,9 @@ static int ar0521_probe(struct i2c_client *client)
>         /* Request optional reset pin (usually active low) and assert it */
>         sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset",
>                                                      GPIOD_OUT_HIGH);
> +       if (IS_ERR(sensor->reset_gpio))
> +               return dev_err_probe(dev, PTR_ERR(sensor->reset_gpio),
> +                                    "failed to get reset gpio\n");
>
>         v4l2_i2c_subdev_init(&sensor->sd, client, &ar0521_subdev_ops);
>

-- 
Krzysztof "Chris" Hałasa

Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa

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

end of thread, other threads:[~2026-02-06  6:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30  4:18 [PATCH] media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe() Chen Ni
2026-01-31  6:24 ` Markus Elfring
2026-02-06  6:39 ` Krzysztof Hałasa

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