All of lore.kernel.org
 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>,
	Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>,
	linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 05/12] pinctrl: nuvoton: ma35: Avoid leaking map when parent node is missing
Date: Thu, 19 Nov 2026 20:49:01 +0000	[thread overview]
Message-ID: <20261119205013.2563811-6-lee@kernel.org> (raw)
In-Reply-To: <20261119205013.2563811-1-lee@kernel.org>

Commit 3fd976afe974 ("pinctrl: nuvoton: fix a double free in
ma35_pinctrl_dt_node_to_map_func()") switched new_map from
devm_kcalloc() to unmanaged kcalloc() without freeing new_map on the
!parent error path.  Because pinctrl_dt_to_map() does not invoke
dt_free_map() when dt_node_to_map() returns an error, new_map is leaked
if of_get_parent() returns NULL.

Look up the parent node before allocating new_map, and release the
parent node reference if the allocation fails.

Fixes: 3fd976afe974 ("pinctrl: nuvoton: fix a double free in ma35_pinctrl_dt_node_to_map_func()")
Closes: https://sashiko.dev/#/bug/linux-ae0c2737-0408-4808-9bae-f7389beb51d0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Correct description of commit 3fd976afe974 in commit message
   (Sashiko)

 drivers/pinctrl/nuvoton/pinctrl-ma35.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index a92945b7821f..92c1c40339f1 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -202,17 +202,19 @@ static int ma35_pinctrl_dt_node_to_map_func(struct pinctrl_dev *pctldev,
 		return -EINVAL;
 	}
 
+	parent = of_get_parent(np);
+	if (!parent)
+		return -EINVAL;
+
 	map_num += grp->grp.npins;
 	new_map = kzalloc_objs(*new_map, map_num);
-	if (!new_map)
+	if (!new_map) {
+		of_node_put(parent);
 		return -ENOMEM;
+	}
 
 	*map = new_map;
 	*num_maps = map_num;
-	/* create mux map */
-	parent = of_get_parent(np);
-	if (!parent)
-		return -EINVAL;
 
 	setting = grp->data;
 
-- 
2.56.1.750.gf70dc682cf-goog


  parent reply	other threads:[~2026-11-19 20:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 20:48 [PATCH v2 00/12] pinctrl: Fix resource leaks, out-of-bounds accesses, and error handling (batch 2) Lee Jones
2026-11-19 20:48 ` [PATCH v2 01/12] pinctrl: nuvoton: ma35: Unmap reg_base and release clock on probe error Lee Jones
2026-11-19 20:48 ` [PATCH v2 02/12] pinctrl: nuvoton: ma35: Prevent out-of-bounds write in ma35_pinctrl_get_soc_data() Lee Jones
2026-11-19 20:48 ` [PATCH v2 03/12] pinctrl: nuvoton: ma35: Retain child firmware node reference " Lee Jones
2026-11-19 20:49 ` [PATCH v2 04/12] pinctrl: nuvoton: ma35: Assign fwnode to gpio_chip in ma35_gpiolib_register() Lee Jones
2026-11-19 20:49 ` Lee Jones [this message]
2026-11-19 20:49 ` [PATCH v2 06/12] pinctrl: nuvoton: Unmap GPIO bank registers on error in NPCM7xx and NPCM8xx Lee Jones
2026-11-19 20:49 ` [PATCH v2 07/12] pinctrl: nuvoton: npcm8xx: Propagate npcm8xx_gpio_register() error in probe Lee Jones
2026-11-19 20:49 ` [PATCH v2 08/12] pinctrl: nuvoton: npcm7xx: Fix fwnode_irq_get() error check in npcm7xx_gpio_of() Lee Jones
2026-11-19 20:49 ` [PATCH v2 09/12] pinctrl: single: Reject invalid register width in pcs_probe() Lee Jones
2026-11-19 22:38   ` Sverdlin, Alexander
2026-11-19 20:49 ` [PATCH v2 10/12] pinctrl: single: Free pinconf settings array in pcs_dt_free_map() Lee Jones
2026-11-19 22:38   ` Sverdlin, Alexander
2026-11-19 20:49 ` [PATCH v2 11/12] pinctrl: sunplus: Validate pin_func index in sppctl_dt_node_to_map() Lee Jones
2026-11-19 20:49 ` [PATCH v2 12/12] pinctrl: realtek: rtd1625: Set dcycle_offset to NA for pins without duty-cycle support Lee Jones

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=20261119205013.2563811-6-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=harshit.m.mogalapalli@oracle.com \
    --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 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.