mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Jacky Huang <ychuang3@nuvoton.com>,
	Shan-Chun Hung <schung@nuvoton.com>,
	Linus Walleij <linusw@kernel.org>,
	linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs
Date: Wed,  2 Dec 2026 09:30:01 +0000	[thread overview]
Message-ID: <6d68d9aecee720a5782091b78b04d4bc33bee19c.1796203691.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796203691.git.lee@kernel.org>

ma35_pinctrl_parse_groups() allocates a single configs array via
pinconf_generic_parse_dt_config() and assigns the same pointer to every
pin in the group.  ma35_pinctrl_dt_node_to_map_func() then copies that
shared pointer into every PIN_MAP_TYPE_CONFIGS_PIN map entry.  Because
ma35_pctrl_ops uses pinconf_generic_dt_free_map(), tearing down the
pinctrl mapping frees the same configs pointer once per pin, causing an
immediate double free and leaving dangling pointers in the group data
for subsequent mappings.  The configs array is also leaked on error
paths in ma35_pinctrl_parse_groups().

Manage the lifetime of the shared configs array with a devm action
registered right after pinconf_generic_parse_dt_config(), and use a
dedicated dt_free_map callback that frees only the map array.

Fixes: f805e356313b ("pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver")
Closes: https://sashiko.dev/#/bug/linux-ec1cf664-4937-4cb3-831c-e2c7838a1aae
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/pinctrl/nuvoton/pinctrl-ma35.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index c20350bc1cdb..b9b34b8b84c6 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 
 #include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinctrl.h>
@@ -236,12 +237,18 @@ static int ma35_pinctrl_dt_node_to_map_func(struct pinctrl_dev *pctldev,
 	return 0;
 }
 
+static void ma35_dt_free_map(struct pinctrl_dev *pctldev,
+			     struct pinctrl_map *map, unsigned int num_maps)
+{
+	kfree(map);
+}
+
 static const struct pinctrl_ops ma35_pctrl_ops = {
 	.get_groups_count = ma35_get_groups_count,
 	.get_group_name = ma35_get_group_name,
 	.get_group_pins = ma35_get_group_pins,
 	.dt_node_to_map = ma35_pinctrl_dt_node_to_map_func,
-	.dt_free_map = pinconf_generic_dt_free_map,
+	.dt_free_map = ma35_dt_free_map,
 };
 
 static int ma35_pinmux_get_func_count(struct pinctrl_dev *pctldev)
@@ -1028,6 +1035,11 @@ static const struct pinconf_ops ma35_pinconf_ops = {
 	.is_generic = true,
 };
 
+static void ma35_free_configs(void *data)
+{
+	kfree(data);
+}
+
 static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_desc *grp,
 				     struct ma35_pinctrl *npctl, u32 index)
 {
@@ -1043,6 +1055,13 @@ static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_
 	if (ret)
 		return ret;
 
+	if (configs) {
+		ret = devm_add_action_or_reset(npctl->dev, ma35_free_configs,
+					       configs);
+		if (ret)
+			return ret;
+	}
+
 	count = fwnode_property_count_u32(fwnode, "nuvoton,pins");
 	if (!count || count % 3)
 		return -EINVAL;
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02  9:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:29 [PATCH 00/12] pinctrl: Fix Critical and High issues reported by Sashiko (batch 3) Lee Jones
2026-12-02  9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
2026-12-02  9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
2026-12-02  9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
2026-12-02 14:08   ` Bartosz Golaszewski
2026-12-02  9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
2026-12-02  9:29 ` [PATCH 05/12] pinctrl: tegra: Require at least one register bank in tegra_pinctrl_probe() Lee Jones
2026-12-02  9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
2026-12-02  9:30 ` Lee Jones [this message]
2026-12-02  9:30 ` [PATCH 08/12] pinctrl: keembay: Check src before calling keembay_find_free_slot() Lee Jones
2026-12-02  9:30 ` [PATCH 09/12] pinctrl: ti: iodelay: Protect generic group addition with pctldev->mutex Lee Jones
2026-12-02  9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
2026-12-02  9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
2026-12-02  9:30 ` [PATCH 12/12] pinctrl: sx150x: Register threaded IRQ after adding GPIO chip Lee Jones
2026-12-02  9:35   ` Neil Armstrong

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=6d68d9aecee720a5782091b78b04d4bc33bee19c.1796203691.git.lee@kernel.org \
    --to=lee@kernel.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=schung@nuvoton.com \
    --cc=stable@vger.kernel.org \
    --cc=ychuang3@nuvoton.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®