]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: pinconf-generic: Fully validate 'pinmux' property
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 17 Mar 2026 10:36:11 +0000 (11:36 +0100)
committerLinus Walleij <linusw@kernel.org>
Thu, 19 Mar 2026 18:21:27 +0000 (19:21 +0100)
The pinconf_generic_parse_dt_pinmux() assumes that the 'pinmux' property
is not empty when present. This might be not true. With that, the allocator
will give a special value in return and not NULL which lead to the crash
when trying to access that (invalid) memory. Fix that by fully validating
'pinmux' value, including its length.

Fixes: 7112c05fff83 ("pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/pinconf-generic.c

index 855ca973a1c8acda60639cbed008f930bf9b6836..6ba44fc0dd82b7d771af6904f859b46a2c8034be 100644 (file)
@@ -325,12 +325,17 @@ int pinconf_generic_parse_dt_pinmux(struct device_node *np, struct device *dev,
                return -ENOENT;
        }
 
+       npins_t = prop->length / sizeof(u32);
+       if (npins_t == 0) {
+               dev_info(dev, "pinmux property doesn't have entries\n");
+               return -ENODATA;
+       }
+
        if (!pid || !pmux || !npins) {
                dev_err(dev, "parameters error\n");
                return -EINVAL;
        }
 
-       npins_t = prop->length / sizeof(u32);
        pid_t = devm_kcalloc(dev, npins_t, sizeof(*pid_t), GFP_KERNEL);
        pmux_t = devm_kcalloc(dev, npins_t, sizeof(*pmux_t), GFP_KERNEL);
        if (!pid_t || !pmux_t) {