* Re: [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
@ 2026-11-27 6:21 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-27 6:21 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
Unfiltered warning: this smatch report is sent as-is and has not been
reviewed for false positives, so please treat it with due skepticism.
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261119232806.4093754-2-alexander.sverdlin@siemens.com>
References: <20261119232806.4093754-2-alexander.sverdlin@siemens.com>
TO: "A. Sverdlin" <alexander.sverdlin@siemens.com>
TO: linux-gpio@vger.kernel.org
CC: Alexander Sverdlin <alexander.sverdlin@siemens.com>
CC: Tony Lindgren <tony@atomide.com>
CC: Haojian Zhuang <haojian.zhuang@linaro.org>
CC: Linus Walleij <linusw@kernel.org>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-omap@vger.kernel.org
CC: linux-kernel@vger.kernel.org
CC: Lee Jones <lee@kernel.org>
CC: stable@vger.kernel.org
Hi Sverdlin,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linux-review/Lee-Jones/pinctrl-nuvoton-ma35-Unmap-reg_base-and-release-clock-on-probe-error/20261119-204857]
url: https://github.com/intel-lab-lkp/linux/commits/A-Sverdlin/pinctrl-single-Also-free-the-pinconf-table-of-a-duplicate-function/20261120-002803
base: https://github.com/intel-lab-lkp/linux Lee-Jones/pinctrl-nuvoton-ma35-Unmap-reg_base-and-release-clock-on-probe-error/20261119-204857
patch link: https://lore.kernel.org/r/20261119232806.4093754-2-alexander.sverdlin%40siemens.com
patch subject: [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
:::::: branch date: 6 days ago
:::::: commit date: 6 days ago
config: sparc-randconfig-2200-20261127 (https://download.01.org/0day-ci/archive/20261127/20261127055733.cfTQXUs7-lkp@intel.com/config)
compiler: sparc-linux-gcc (GCC) 12.5.0
smatch: v0.5.0-9187-g5189e3fb
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/20261127055733.cfTQXUs7-lkp@intel.com/
New smatch warnings:
drivers/pinctrl/pinctrl-single.c:1111 pcs_parse_one_pinctrl_entry() error: we previously assumed 'function' could be null (see line 1090)
Old smatch warnings:
drivers/pinctrl/pinctrl-single.c:1038 pcs_parse_one_pinctrl_entry() warn: missing unwind goto?
drivers/pinctrl/pinctrl-single.c:1180 pcs_parse_bits_in_pinctrl_entry() warn: missing unwind goto?
drivers/pinctrl/pinctrl-single.c:1659 pcs_irq_init_chained_handler() warn: 'pcs_soc->irq' from request_irq() not released on lines: 1656.
vim +/function +1111 drivers/pinctrl/pinctrl-single.c
9dddb4df90d1364 Haojian Zhuang 2013-02-17 986
8b8b091bf07fa7e Tony Lindgren 2012-07-10 987 /**
bc6d201591344aa Drew Fustini 2020-06-17 988 * pcs_parse_one_pinctrl_entry() - parses a device tree mux entry
8b8b091bf07fa7e Tony Lindgren 2012-07-10 989 * @pcs: pinctrl driver instance
8b8b091bf07fa7e Tony Lindgren 2012-07-10 990 * @np: device node of the mux entry
8b8b091bf07fa7e Tony Lindgren 2012-07-10 991 * @map: map entry
9dddb4df90d1364 Haojian Zhuang 2013-02-17 992 * @num_maps: number of map
8b8b091bf07fa7e Tony Lindgren 2012-07-10 993 * @pgnames: pingroup names
8b8b091bf07fa7e Tony Lindgren 2012-07-10 994 *
8b8b091bf07fa7e Tony Lindgren 2012-07-10 995 * Note that this binding currently supports only sets of one register + value.
8b8b091bf07fa7e Tony Lindgren 2012-07-10 996 *
8b8b091bf07fa7e Tony Lindgren 2012-07-10 997 * Also note that this driver tries to avoid understanding pin and function
8b8b091bf07fa7e Tony Lindgren 2012-07-10 998 * names because of the extra bloat they would cause especially in the case of
8b8b091bf07fa7e Tony Lindgren 2012-07-10 999 * a large number of pins. This driver just sets what is specified for the board
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1000 * in the .dts file. Further user space debugging tools can be developed to
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1001 * decipher the pin and function names using debugfs.
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1002 *
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1003 * If you are concerned about the boot time, set up the static pins in
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1004 * the bootloader, and only set up selected pins as device tree entries.
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1005 */
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1006 static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1007 struct device_node *np,
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1008 struct pinctrl_map **map,
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1009 unsigned *num_maps,
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1010 const char **pgnames)
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1011 {
4622215fb1dda40 Tony Lindgren 2016-11-03 1012 const char *name = "pinctrl-single,pins";
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1013 struct pcs_func_vals *vals;
a4ab10860723652 Tony Lindgren 2018-07-05 1014 int rows, *pins, found = 0, res = -ENOMEM, i, fsel, gsel;
a4ab10860723652 Tony Lindgren 2018-07-05 1015 struct pcs_function *function = NULL;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1016
4622215fb1dda40 Tony Lindgren 2016-11-03 1017 rows = pinctrl_count_index_with_args(np, name);
de7416bcee3f7c9 Axel Haslam 2016-11-09 1018 if (rows <= 0) {
059a6e630bb9ee2 Colin Ian King 2016-12-23 1019 dev_err(pcs->dev, "Invalid number of rows: %d\n", rows);
de7416bcee3f7c9 Axel Haslam 2016-11-09 1020 return -EINVAL;
de7416bcee3f7c9 Axel Haslam 2016-11-09 1021 }
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1022
a86854d0c599b32 Kees Cook 2018-06-12 1023 vals = devm_kcalloc(pcs->dev, rows, sizeof(*vals), GFP_KERNEL);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1024 if (!vals)
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1025 return -ENOMEM;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1026
a86854d0c599b32 Kees Cook 2018-06-12 1027 pins = devm_kcalloc(pcs->dev, rows, sizeof(*pins), GFP_KERNEL);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1028 if (!pins)
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1029 goto free_vals;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1030
4622215fb1dda40 Tony Lindgren 2016-11-03 1031 for (i = 0; i < rows; i++) {
4622215fb1dda40 Tony Lindgren 2016-11-03 1032 struct of_phandle_args pinctrl_spec;
4622215fb1dda40 Tony Lindgren 2016-11-03 1033 unsigned int offset;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1034 int pin;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1035
4622215fb1dda40 Tony Lindgren 2016-11-03 1036 res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec);
4622215fb1dda40 Tony Lindgren 2016-11-03 1037 if (res)
4622215fb1dda40 Tony Lindgren 2016-11-03 1038 return res;
4622215fb1dda40 Tony Lindgren 2016-11-03 1039
9b9448f39e83d8e Drew Fustini 2020-09-30 1040 if (pinctrl_spec.args_count < 2 || pinctrl_spec.args_count > 3) {
4622215fb1dda40 Tony Lindgren 2016-11-03 1041 dev_err(pcs->dev, "invalid args_count for spec: %i\n",
4622215fb1dda40 Tony Lindgren 2016-11-03 1042 pinctrl_spec.args_count);
4622215fb1dda40 Tony Lindgren 2016-11-03 1043 break;
4622215fb1dda40 Tony Lindgren 2016-11-03 1044 }
4622215fb1dda40 Tony Lindgren 2016-11-03 1045
4622215fb1dda40 Tony Lindgren 2016-11-03 1046 offset = pinctrl_spec.args[0];
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1047 vals[found].reg = pcs->base + offset;
a133954188887a8 Drew Fustini 2020-07-01 1048
a133954188887a8 Drew Fustini 2020-07-01 1049 switch (pinctrl_spec.args_count) {
a133954188887a8 Drew Fustini 2020-07-01 1050 case 2:
4622215fb1dda40 Tony Lindgren 2016-11-03 1051 vals[found].val = pinctrl_spec.args[1];
a133954188887a8 Drew Fustini 2020-07-01 1052 break;
a133954188887a8 Drew Fustini 2020-07-01 1053 case 3:
a133954188887a8 Drew Fustini 2020-07-01 1054 vals[found].val = (pinctrl_spec.args[1] | pinctrl_spec.args[2]);
a133954188887a8 Drew Fustini 2020-07-01 1055 break;
a133954188887a8 Drew Fustini 2020-07-01 1056 }
4622215fb1dda40 Tony Lindgren 2016-11-03 1057
94f4e54cecaf3ec Rob Herring 2018-08-27 1058 dev_dbg(pcs->dev, "%pOFn index: 0x%x value: 0x%x\n",
f4a2b19c37caf40 Drew Fustini 2020-09-14 1059 pinctrl_spec.np, offset, vals[found].val);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1060
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1061 pin = pcs_get_pin_by_offset(pcs, offset);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1062 if (pin < 0) {
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1063 dev_err(pcs->dev,
94f4e54cecaf3ec Rob Herring 2018-08-27 1064 "could not add functions for %pOFn %ux\n",
94f4e54cecaf3ec Rob Herring 2018-08-27 1065 np, offset);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1066 break;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1067 }
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1068 pins[found++] = pin;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1069 }
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1070
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1071 pgnames[0] = np->name;
a4ab10860723652 Tony Lindgren 2018-07-05 1072 mutex_lock(&pcs->mutex);
a4ab10860723652 Tony Lindgren 2018-07-05 1073 fsel = pcs_add_function(pcs, &function, np->name, vals, found,
a4ab10860723652 Tony Lindgren 2018-07-05 1074 pgnames, 1);
a4ab10860723652 Tony Lindgren 2018-07-05 1075 if (fsel < 0) {
a4ab10860723652 Tony Lindgren 2018-07-05 1076 res = fsel;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1077 goto free_pins;
712778d02d5c24e Dan Carpenter 2016-11-16 1078 }
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1079
a4ab10860723652 Tony Lindgren 2018-07-05 1080 gsel = pinctrl_generic_add_group(pcs->pctl, np->name, pins, found, pcs);
a4ab10860723652 Tony Lindgren 2018-07-05 1081 if (gsel < 0) {
a4ab10860723652 Tony Lindgren 2018-07-05 1082 res = gsel;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1083 goto free_function;
a4ab10860723652 Tony Lindgren 2018-07-05 1084 }
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1085
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1086 (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1087 (*map)->data.mux.group = np->name;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1088 (*map)->data.mux.function = np->name;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1089
a4ab10860723652 Tony Lindgren 2018-07-05 @1090 if (PCS_HAS_PINCONF && function) {
18442e65d424dc8 Wei Yongjun 2013-05-07 1091 res = pcs_parse_pinconf(pcs, np, function, map);
f46fe79ff1b6569 Drew Fustini 2020-06-08 1092 if (res == 0)
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1093 *num_maps = 2;
f46fe79ff1b6569 Drew Fustini 2020-06-08 1094 else if (res == -ENOTSUPP)
f46fe79ff1b6569 Drew Fustini 2020-06-08 1095 *num_maps = 1;
f46fe79ff1b6569 Drew Fustini 2020-06-08 1096 else
f46fe79ff1b6569 Drew Fustini 2020-06-08 1097 goto free_pingroups;
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1098 } else {
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1099 *num_maps = 1;
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1100 }
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1101
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1102 /*
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1103 * The core deduplicates groups/functions by name and keeps the first
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1104 * for the controller's lifetime; drop our now-redundant copies when the
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1105 * node is mapped again (consumer re-probe). The group is deduplicated
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1106 * together with the function, so testing the latter is enough.
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1107 */
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1108 if (pinmux_generic_get_function(pcs->pctl, fsel)->data != function) {
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1109 devm_kfree(pcs->dev, pins);
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1110 devm_kfree(pcs->dev, vals);
56403881c93a331 Alexander Sverdlin 2026-11-20 @1111 devm_kfree(pcs->dev, function->conf);
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1112 devm_kfree(pcs->dev, function);
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1113 devm_kfree(pcs->dev, pgnames);
ad2093840ca3bad Alexander Sverdlin 2026-10-01 1114 }
a4ab10860723652 Tony Lindgren 2018-07-05 1115 mutex_unlock(&pcs->mutex);
a4ab10860723652 Tony Lindgren 2018-07-05 1116
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1117 return 0;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1118
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1119 free_pingroups:
a4ab10860723652 Tony Lindgren 2018-07-05 1120 pinctrl_generic_remove_group(pcs->pctl, gsel);
9dddb4df90d1364 Haojian Zhuang 2013-02-17 1121 *num_maps = 1;
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1122 free_function:
a4ab10860723652 Tony Lindgren 2018-07-05 1123 pinmux_generic_remove_function(pcs->pctl, fsel);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1124 free_pins:
673ba5a05ca14c2 Wei Yongjun 2018-07-11 1125 mutex_unlock(&pcs->mutex);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1126 devm_kfree(pcs->dev, pins);
8b8b091bf07fa7e Tony Lindgren 2012-07-10 1127
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1128 free_vals:
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1129 devm_kfree(pcs->dev, vals);
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1130
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1131 return res;
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1132 }
4e7e8017a80e181 Manjunathappa, Prakash 2013-05-21 1133
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 0/3] pinctrl: single: follow-up fixes from review
@ 2026-11-19 23:28 A. Sverdlin
2026-11-19 23:28 ` [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function A. Sverdlin
0 siblings, 1 reply; 4+ messages in thread
From: A. Sverdlin @ 2026-11-19 23:28 UTC (permalink / raw)
To: linux-gpio
Cc: Alexander Sverdlin, Tony Lindgren, Haojian Zhuang, Linus Walleij,
linux-arm-kernel, linux-omap, linux-kernel, Lee Jones
From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
These are follow-ups to commit ad2093840ca3 ("pinctrl: single: don't leak
group/function tables on consumer re-probe") in pinctrl/for-next, which
this series is based on. All three issues were found in code review
(partly while reviewing Lee's recent pinctrl-single series [1]). None of
them was reproduced, so the series is compile-tested only (W=1, ARM).
1/3 is a gap in ad2093840ca3 itself: the duplicate function is freed, but
its pinconf table isn't. My re-probe testing of ad2093840ca3 (TPM
bind/unbind loop on an AM625 board, watching the slab counters) could not
have shown it. That controller is plain "pinctrl-single" without
PCS_FEAT_PINCONF, so pcs_parse_pinconf() never runs there. kmemleak
doesn't see it either, because the table stays reachable through devres.
2/3 fixes error paths that remove a group/function the core deduplicated,
i.e. one still used by an earlier mapping. Reaching them needs an
allocation failure during a consumer re-probe.
3/3 rejects bit-per-mux without a usable function mask. Such DTs pass
dt-validate but divide by zero at runtime. Checked with dt-validate and
against all in-tree bit-per-mux users, but not booted.
[1] https://lore.kernel.org/all/20261119205013.2563811-10-lee@kernel.org/
Alexander Sverdlin (3):
pinctrl: single: Also free the pinconf table of a duplicate function
pinctrl: single: Don't remove deduplicated groups and functions on
error
pinctrl: single: Reject bit-per-mux without a usable function mask
drivers/pinctrl/pinctrl-single.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
2026-11-19 23:28 [PATCH 0/3] pinctrl: single: follow-up fixes from review A. Sverdlin
@ 2026-11-19 23:28 ` A. Sverdlin
2026-11-19 23:43 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: A. Sverdlin @ 2026-11-19 23:28 UTC (permalink / raw)
To: linux-gpio
Cc: Alexander Sverdlin, Tony Lindgren, Haojian Zhuang, Linus Walleij,
linux-arm-kernel, linux-omap, linux-kernel, Lee Jones, stable
From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
pcs_parse_pinconf() attaches a devm-allocated pcs_conf_vals array to the
function pcs_add_function() has just allocated. When a node is mapped
again, e.g. on consumer re-probe, that function is a duplicate of the one
the core keeps and is freed since commit ad2093840ca3 ("pinctrl: single:
don't leak group/function tables on consumer re-probe"), but its conf
array stays on the controller's devres list. It accumulates with every
re-probe of a consumer whose pin group has pinconf properties, until the
controller is unbound.
Free it together with the function.
Fixes: 9dddb4df90d1 ("pinctrl: single: support generic pinconf")
Cc: stable@vger.kernel.org
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
---
drivers/pinctrl/pinctrl-single.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index d72ebb186b894..64472465800c4 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1107,6 +1107,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
if (pinmux_generic_get_function(pcs->pctl, fsel)->data != function) {
devm_kfree(pcs->dev, pins);
devm_kfree(pcs->dev, vals);
+ devm_kfree(pcs->dev, function->conf);
devm_kfree(pcs->dev, function);
devm_kfree(pcs->dev, pgnames);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
2026-11-19 23:28 ` [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function A. Sverdlin
@ 2026-11-19 23:43 ` sashiko-bot
2026-11-20 9:06 ` Sverdlin, Alexander
0 siblings, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-19 23:43 UTC (permalink / raw)
To: A. Sverdlin, linux-gpio
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] pinctrl: single: use-after-free in
pcs_parse_one_pinctrl_entry() [1]
--
commit f9a80b7d4b1cc004ae636f5e91a037b0d6afbc93
Author: Alexander Sverdlin <alexander.sverdlin@siemens.com>
pinctrl: single: Also free the pinconf table of a duplicate function
This commit frees function->conf when pcs_parse_one_pinctrl_entry() drops
a duplicate function on consumer re-probe.
> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> index 52734bd7b7f06..95c8bd38459c8 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -1102,6 +1102,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
> if (pinmux_generic_get_function(pcs->pctl, fsel)->data != function) {
> devm_kfree(pcs->dev, pins);
> devm_kfree(pcs->dev, vals);
> + devm_kfree(pcs->dev, function->conf);
> devm_kfree(pcs->dev, function);
> devm_kfree(pcs->dev, pgnames);
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can the error path in
pcs_parse_one_pinctrl_entry() (and pcs_parse_bits_in_pinctrl_entry())
remove an already registered group and function [1] and cause a
use-after-free?
When a duplicate node is parsed, pcs_add_function() and
pinctrl_generic_add_group() return the existing selectors fsel and gsel.
If pcs_parse_pinconf() then fails, the error path unconditionally removes
both selectors from the core radix trees:
drivers/pinctrl/pinctrl-single.c:pcs_parse_one_pinctrl_entry() {
...
if (PCS_HAS_PINCONF && function) {
res = pcs_parse_pinconf(pcs, np, function, map);
if (res == 0)
*num_maps = 2;
else if (res == -ENOTSUPP)
*num_maps = 1;
else
goto free_pingroups;
}
...
free_pingroups:
pinctrl_generic_remove_group(pcs->pctl, gsel);
*num_maps = 1;
free_function:
pinmux_generic_remove_function(pcs->pctl, fsel);
...
}
This deletes the original group and function descriptors while active
consumers still reference them, and leaks the duplicate function,
pgnames, and function->conf allocations.
[1] https://sashiko.dev/#/bug/linux-146c577c-dec4-4dc4-b28e-826c1cc76a9a
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119232806.4093754-1-alexander.sverdlin@siemens.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
2026-11-19 23:43 ` sashiko-bot
@ 2026-11-20 9:06 ` Sverdlin, Alexander
0 siblings, 0 replies; 4+ messages in thread
From: Sverdlin, Alexander @ 2026-11-20 9:06 UTC (permalink / raw)
To: sashiko-reviews@lists.linux.dev, linux-gpio@vger.kernel.org
Hi!
On Thu, 2026-11-19 at 23:43 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [Critical] pinctrl: single: use-after-free in
> pcs_parse_one_pinctrl_entry() [1]
> --
>
> commit f9a80b7d4b1cc004ae636f5e91a037b0d6afbc93
> Author: Alexander Sverdlin <alexander.sverdlin@siemens.com>
>
> pinctrl: single: Also free the pinconf table of a duplicate function
>
> This commit frees function->conf when pcs_parse_one_pinctrl_entry() drops
> a duplicate function on consumer re-probe.
>
> > diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> > index 52734bd7b7f06..95c8bd38459c8 100644
> > --- a/drivers/pinctrl/pinctrl-single.c
> > +++ b/drivers/pinctrl/pinctrl-single.c
> > @@ -1102,6 +1102,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
> > if (pinmux_generic_get_function(pcs->pctl, fsel)->data != function) {
> > devm_kfree(pcs->dev, pins);
> > devm_kfree(pcs->dev, vals);
> > + devm_kfree(pcs->dev, function->conf);
> > devm_kfree(pcs->dev, function);
> > devm_kfree(pcs->dev, pgnames);
> > }
>
> [Severity: Critical]
> This problem wasn't introduced by this patch, but can the error path in
> pcs_parse_one_pinctrl_entry() (and pcs_parse_bits_in_pinctrl_entry())
> remove an already registered group and function [1] and cause a
> use-after-free?
>
> When a duplicate node is parsed, pcs_add_function() and
> pinctrl_generic_add_group() return the existing selectors fsel and gsel.
> If pcs_parse_pinconf() then fails, the error path unconditionally removes
> both selectors from the core radix trees:
>
> drivers/pinctrl/pinctrl-single.c:pcs_parse_one_pinctrl_entry() {
> ...
> if (PCS_HAS_PINCONF && function) {
> res = pcs_parse_pinconf(pcs, np, function, map);
> if (res == 0)
> *num_maps = 2;
> else if (res == -ENOTSUPP)
> *num_maps = 1;
> else
> goto free_pingroups;
> }
> ...
> free_pingroups:
> pinctrl_generic_remove_group(pcs->pctl, gsel);
> *num_maps = 1;
> free_function:
> pinmux_generic_remove_function(pcs->pctl, fsel);
> ...
> }
>
> This deletes the original group and function descriptors while active
> consumers still reference them, and leaks the duplicate function,
> pgnames, and function->conf allocations.
>
> [1] https://sashiko.dev/#/bug/linux-146c577c-dec4-4dc4-b28e-826c1cc76a9a
Yes, I considered this issue real as well and addressed it in patch [2/3]
of my series.
[2/3] https://lore.kernel.org/all/20261119232806.4093754-3-alexander.sverdlin@siemens.com/
--
Alexander Sverdlin
Siemens AG
www.siemens.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-27 6:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 6:21 [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2026-11-19 23:28 [PATCH 0/3] pinctrl: single: follow-up fixes from review A. Sverdlin
2026-11-19 23:28 ` [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function A. Sverdlin
2026-11-19 23:43 ` sashiko-bot
2026-11-20 9:06 ` Sverdlin, Alexander
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.