]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: i2c: ar0521: Check return value of devm_gpiod_get_optional() in ar0521_probe()
authorChen Ni <nichen@iscas.ac.cn>
Fri, 30 Jan 2026 04:18:15 +0000 (12:18 +0800)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 11 Mar 2026 00:05:38 +0000 (01:05 +0100)
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>
Acked-by: Krzysztof HaƂasa <khalasa@piap.pl>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/i2c/ar0521.c

index f156058500e3dce5d7b5b831bf8ec4056e49ad5b..ed324c2d87aa25c737c7359cfe8bad9378e25287 100644 (file)
@@ -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);