From: "A. Sverdlin" <alexander.sverdlin@siemens.com>
To: linux-gpio@vger.kernel.org
Cc: Alexander Sverdlin <alexander.sverdlin@siemens.com>,
Tony Lindgren <tony@atomide.com>,
Haojian Zhuang <haojian.zhuang@linaro.org>,
Linus Walleij <linusw@kernel.org>,
Lokesh Vutla <lokeshvutla@ti.com>, Nishanth Menon <nm@ti.com>,
Rob Herring <robh@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/2] pinctrl: single: don't leak group/function tables on consumer re-probe
Date: Thu, 1 Oct 2026 10:52:10 +0200 [thread overview]
Message-ID: <20261001085217.1778645-2-alexander.sverdlin@siemens.com> (raw)
In-Reply-To: <20261001085217.1778645-1-alexander.sverdlin@siemens.com>
From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
For every mapping pcs_parse_{one,bits}_in_pinctrl_entry() builds a
pcs_function, a value table, a pin array and a pingroup-name array and
registers them via pcs_add_function()/pinctrl_generic_add_group(). The
core deduplicates groups and functions by name and keeps the first
instance for the controller's lifetime, so the tables built for any later
mapping of the same node - e.g. each consumer re-probe - are dropped by
the core and leaked.
Free the redundant copies once the function turns out to be a duplicate;
the group is deduplicated together with it. Don't remove the deduplicated
instance from the core: its selector is a plain counter (num_groups /
num_functions), so removing any but the last entry corrupts the selector
space.
kmemleak stays silent because the leaked tables remain reachable from the
controller's devres list.
Fixes: 8b8b091bf07f ("pinctrl: Add one-register-per-pin type device tree based pinctrl driver")
Cc: stable@vger.kernel.org
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
---
drivers/pinctrl/pinctrl-single.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index e0eb7240a9859..e75e32723100d 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1097,6 +1097,19 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
} else {
*num_maps = 1;
}
+
+ /*
+ * The core deduplicates groups/functions by name and keeps the first
+ * for the controller's lifetime; drop our now-redundant copies when the
+ * node is mapped again (consumer re-probe). The group is deduplicated
+ * together with the function, so testing the latter is enough.
+ */
+ 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);
+ devm_kfree(pcs->dev, pgnames);
+ }
mutex_unlock(&pcs->mutex);
return 0;
@@ -1235,6 +1248,14 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
(*map)->data.mux.function = np->name;
*num_maps = 1;
+
+ /* See pcs_parse_one_pinctrl_entry() for the deduplication rationale. */
+ 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);
+ devm_kfree(pcs->dev, pgnames);
+ }
mutex_unlock(&pcs->mutex);
return 0;
--
2.55.0
next prev parent reply other threads:[~2026-10-01 8:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 8:52 [PATCH 0/2] pinctrl: fix group/function table leaks " A. Sverdlin
2026-10-01 8:52 ` A. Sverdlin [this message]
2026-10-01 8:52 ` [PATCH 2/2] pinctrl: ti-iodelay: fix memory " A. Sverdlin
2026-11-04 12:30 ` [PATCH 0/2] pinctrl: fix group/function table " Linus Walleij
2026-11-04 12:59 ` Sverdlin, Alexander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261001085217.1778645-2-alexander.sverdlin@siemens.com \
--to=alexander.sverdlin@siemens.com \
--cc=haojian.zhuang@linaro.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=lokeshvutla@ti.com \
--cc=nm@ti.com \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®