* [PATCH v1 1/3] pinctrl: pinconf-generic: Fully validate 'pinmux' property
2026-03-17 10:36 [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Andy Shevchenko
@ 2026-03-17 10:36 ` Andy Shevchenko
2026-03-17 10:36 ` [PATCH v1 2/3] pinctrl: pinconf-generic: Validate fwnode instead of device node Andy Shevchenko
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-17 10:36 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, linux-kernel; +Cc: Andy Shevchenko
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>
---
drivers/pinctrl/pinconf-generic.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index 61b5b3fb94ce..d0b825ff52db 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -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) {
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 2/3] pinctrl: pinconf-generic: Validate fwnode instead of device node
2026-03-17 10:36 [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Andy Shevchenko
2026-03-17 10:36 ` [PATCH v1 1/3] pinctrl: pinconf-generic: Fully validate 'pinmux' property Andy Shevchenko
@ 2026-03-17 10:36 ` Andy Shevchenko
2026-03-17 10:36 ` [PATCH v1 3/3] pinctrl: pinconf-generic: Convert ..._parse_dt_pinmux() to fwnode API Andy Shevchenko
2026-03-19 18:22 ` [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-17 10:36 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, linux-kernel; +Cc: Andy Shevchenko
Currently we convert device node to fwnode in the
pinconf_generic_parse_dt_config() and then validate the device node.
This is confusing order. Instead, assign fwnode and validate it.
Fixes: e002d162654b ("pinctrl: pinconf-generic: Use only fwnode API in parse_dt_cfg()")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pinctrl/pinconf-generic.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index d0b825ff52db..0ed57720ae61 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -377,12 +377,13 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
unsigned long **configs,
unsigned int *nconfigs)
{
- struct fwnode_handle *fwnode = of_fwnode_handle(np);
unsigned long *cfg;
unsigned int max_cfg, ncfg = 0;
+ struct fwnode_handle *fwnode;
int ret;
- if (!np)
+ fwnode = of_fwnode_handle(np);
+ if (!fwnode)
return -EINVAL;
/* allocate a temporary array big enough to hold one of each option */
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 3/3] pinctrl: pinconf-generic: Convert ..._parse_dt_pinmux() to fwnode API
2026-03-17 10:36 [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Andy Shevchenko
2026-03-17 10:36 ` [PATCH v1 1/3] pinctrl: pinconf-generic: Fully validate 'pinmux' property Andy Shevchenko
2026-03-17 10:36 ` [PATCH v1 2/3] pinctrl: pinconf-generic: Validate fwnode instead of device node Andy Shevchenko
@ 2026-03-17 10:36 ` Andy Shevchenko
2026-03-19 18:22 ` [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-17 10:36 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, linux-kernel; +Cc: Andy Shevchenko
Convert pinconf_generic_parse_dt_pinmux() to fwnode API. This makes code
cleaner and potentially reusable for some other types of fwnodes, such as
software nodes.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pinctrl/pinconf-generic.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index 0ed57720ae61..88eacd1aa2de 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -312,20 +312,19 @@ int pinconf_generic_parse_dt_pinmux(struct device_node *np, struct device *dev,
unsigned int **pid, unsigned int **pmux,
unsigned int *npins)
{
+ struct fwnode_handle *fwnode = of_fwnode_handle(np);
unsigned int *pid_t;
unsigned int *pmux_t;
- struct property *prop;
unsigned int npins_t, i;
- u32 value;
int ret;
- prop = of_find_property(np, "pinmux", NULL);
- if (!prop) {
+ ret = fwnode_property_count_u32(fwnode, "pinmux");
+ if (ret < 0) {
dev_info(dev, "Missing pinmux property\n");
- return -ENOENT;
+ return ret;
}
- npins_t = prop->length / sizeof(u32);
+ npins_t = ret;
if (npins_t == 0) {
dev_info(dev, "pinmux property doesn't have entries\n");
return -ENODATA;
@@ -342,14 +341,16 @@ int pinconf_generic_parse_dt_pinmux(struct device_node *np, struct device *dev,
dev_err(dev, "kalloc memory fail\n");
return -ENOMEM;
}
+
+ ret = fwnode_property_read_u32_array(fwnode, "pinmux", pmux_t, npins_t);
+ if (ret) {
+ dev_err(dev, "get pinmux value fail\n");
+ goto exit;
+ }
+
for (i = 0; i < npins_t; i++) {
- ret = of_property_read_u32_index(np, "pinmux", i, &value);
- if (ret) {
- dev_err(dev, "get pinmux value fail\n");
- goto exit;
- }
- pmux_t[i] = value & 0xff;
- pid_t[i] = (value >> 8) & 0xffffff;
+ pid_t[i] = pmux_t[i] >> 8;
+ pmux_t[i] = pmux_t[i] & 0xff;
}
*pid = pid_t;
*pmux = pmux_t;
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions
2026-03-17 10:36 [PATCH v1 0/3] pinctrl: pinconf-generic: More fwnode related conversions Andy Shevchenko
` (2 preceding siblings ...)
2026-03-17 10:36 ` [PATCH v1 3/3] pinctrl: pinconf-generic: Convert ..._parse_dt_pinmux() to fwnode API Andy Shevchenko
@ 2026-03-19 18:22 ` Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-03-19 18:22 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel
On Tue, Mar 17, 2026 at 11:38 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> While I have noticed some inconsistencies in the pinconf-generic code,
> I also found one minor issue and a room to convert the code to use
> fwnode APIs instead of being too OF-centric. This might help in the future
> to use similar data structures in software nodes.
>
> Andy Shevchenko (3):
> pinctrl: pinconf-generic: Fully validate 'pinmux' property
> pinctrl: pinconf-generic: Validate fwnode instead of device node
> pinctrl: pinconf-generic: Convert ..._parse_dt_pinmux() to fwnode API
Patches applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread