]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: i2c: mt9p031: Check return value of devm_gpiod_get_optional() in mt9p031_probe()
authorChen Ni <nichen@iscas.ac.cn>
Mon, 2 Feb 2026 02:43:12 +0000 (10:43 +0800)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 11 Mar 2026 00:05:37 +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>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/i2c/mt9p031.c

index 1500ee4db47ec7ddb2aa36c0f74ffd116726b3eb..ea5d43d925ffa8b05da6e428916994deb9d4dc6c 100644 (file)
@@ -1183,6 +1183,10 @@ static int mt9p031_probe(struct i2c_client *client)
 
        mt9p031->reset = devm_gpiod_get_optional(&client->dev, "reset",
                                                 GPIOD_OUT_HIGH);
+       if (IS_ERR(mt9p031->reset)) {
+               ret = PTR_ERR(mt9p031->reset);
+               goto done;
+       }
 
        ret = mt9p031_clk_setup(mt9p031);
        if (ret)