mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 2/2] pinctrl: ti-iodelay: fix memory leaks on consumer re-probe
Date: Thu,  1 Oct 2026 10:52:11 +0200	[thread overview]
Message-ID: <20261001085217.1778645-3-alexander.sverdlin@siemens.com> (raw)
In-Reply-To: <20261001085217.1778645-1-alexander.sverdlin@siemens.com>

From: Alexander Sverdlin <alexander.sverdlin@siemens.com>

ti_iodelay_dt_node_to_map() allocates a pinctrl_map, a group, a pin array
and a config array per mapping with devres on the controller, and registers
the group via pinctrl_generic_add_group(). The core deduplicates groups by
name and keeps the first for the controller's lifetime, so on a repeated
mapping of the same node (consumer re-probe) the freshly built group, pins
and configs are dropped and leaked. The pinctrl_map leaked too: the driver
never implemented pinctrl_ops::dt_free_map, so nothing released it.

Reuse the deduplicated group and free the redundant copy (repointing the
map at the retained group), and add dt_free_map() to release the map.

Fixes: 003910ebc83b ("pinctrl: Introduce TI IOdelay configuration driver")
Cc: stable@vger.kernel.org
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
---
 drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index 019b302db2b00..9a8865ce0bbab 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -497,6 +497,7 @@ static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
 	struct ti_iodelay_device *iod;
 	struct ti_iodelay_cfg *cfg;
 	struct ti_iodelay_pingroup *g;
+	struct group_desc *grp;
 	const char *name = "pinctrl-pin-array";
 	int rows, *pins, error = -EINVAL, i;
 
@@ -553,6 +554,19 @@ static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
 	if (error < 0)
 		goto free_data;
 
+	/*
+	 * The core deduplicates groups by name and keeps the first for the
+	 * controller's lifetime; on a repeated mapping (consumer re-probe)
+	 * reuse it and free our now-redundant copy.
+	 */
+	grp = pinctrl_generic_get_group(iod->pctl, error);
+	if (grp->data != g) {
+		devm_kfree(iod->dev, cfg);
+		devm_kfree(iod->dev, pins);
+		devm_kfree(iod->dev, g);
+		g = grp->data;
+	}
+
 	(*map)->type = PIN_MAP_TYPE_CONFIGS_GROUP;
 	(*map)->data.configs.group_or_pin = np->name;
 	(*map)->data.configs.configs = &g->config;
@@ -722,6 +736,15 @@ static void ti_iodelay_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
 }
 #endif
 
+static void ti_iodelay_dt_free_map(struct pinctrl_dev *pctldev,
+				   struct pinctrl_map *map, unsigned int num_maps)
+{
+	struct ti_iodelay_device *iod;
+
+	iod = pinctrl_dev_get_drvdata(pctldev);
+	devm_kfree(iod->dev, map);
+}
+
 static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
 	.get_groups_count = pinctrl_generic_get_group_count,
 	.get_group_name = pinctrl_generic_get_group_name,
@@ -730,6 +753,7 @@ static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
 	.pin_dbg_show = ti_iodelay_pin_dbg_show,
 #endif
 	.dt_node_to_map = ti_iodelay_dt_node_to_map,
+	.dt_free_map = ti_iodelay_dt_free_map,
 };
 
 static const struct pinconf_ops ti_iodelay_pinctrl_pinconf_ops = {
-- 
2.55.0


      parent reply	other threads:[~2026-10-01  8:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01  8:52 [PATCH 0/2] pinctrl: fix group/function table " A. Sverdlin
2026-10-01  8:52 ` [PATCH 1/2] pinctrl: single: don't leak group/function tables " A. Sverdlin
2026-10-01  8:52 ` A. Sverdlin [this message]

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-3-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®