]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mfd: ene-kb3930: Fix a potential NULL pointer dereference
authorChenyuan Yang <chenyuan0y@gmail.com>
Mon, 24 Feb 2025 23:37:36 +0000 (17:37 -0600)
committerLee Jones <lee@kernel.org>
Fri, 14 Mar 2025 08:59:07 +0000 (08:59 +0000)
The off_gpios could be NULL. Add missing check in the kb3930_probe().
This is similar to the issue fixed in commit b1ba8bcb2d1f
("backlight: hx8357: Fix potential NULL pointer dereference").

This was detected by our static analysis tool.

Cc: stable@vger.kernel.org
Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller")
Suggested-by: Lee Jones <lee@kernel.org>
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Link: https://lore.kernel.org/r/20250224233736.1919739-1-chenyuan0y@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/mfd/ene-kb3930.c

index fa0ad2f14a396189a2df066072096ff90456ae7c..9460a67acb0b5e3ce09e99e96625af72e26d07b2 100644 (file)
@@ -162,7 +162,7 @@ static int kb3930_probe(struct i2c_client *client)
                        devm_gpiod_get_array_optional(dev, "off", GPIOD_IN);
                if (IS_ERR(ddata->off_gpios))
                        return PTR_ERR(ddata->off_gpios);
-               if (ddata->off_gpios->ndescs < 2) {
+               if (ddata->off_gpios && ddata->off_gpios->ndescs < 2) {
                        dev_err(dev, "invalid off-gpios property\n");
                        return -EINVAL;
                }