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 v2 01/12] pinctrl: nuvoton: ma35: Unmap reg_base and release clock on probe error
Date: Thu, 19 Nov 2026 20:48:57 +0000 [thread overview]
Message-ID: <20261119205013.2563811-2-lee@kernel.org> (raw)
In-Reply-To: <20261119205013.2563811-1-lee@kernel.org>
ma35_get_bank_data() maps bank->reg_base via fwnode_iomap() and acquires
and enables bank->clk via of_clk_get() and clk_prepare_enable(), neither
of which is devres-managed. If of_clk_get() or clk_prepare_enable()
fails, bank->reg_base is leaked, and ma35_pinctrl_get_soc_data() ignores
the error and continues probing with an uninitialised bank.
Register devm cleanup actions for bank->reg_base and bank->clk, and
propagate errors from ma35_get_bank_data() in
ma35_pinctrl_get_soc_data().
Fixes: f805e356313b ("pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver")
Closes: https://sashiko.dev/#/bug/linux-2046e6c6-45d1-42d4-ae9f-27fac33b07e7
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2: Explicitly include the I/O mapping header for iounmap()
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 37 ++++++++++++++++++++++----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index a79ebf4be2c3..bfa743db8b13 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -11,6 +11,7 @@
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/gpio/driver.h>
+#include <linux/io.h>
#include <linux/mfd/syscon.h>
#include <linux/of.h>
#include <linux/platform_device.h>
@@ -555,6 +556,22 @@ static int ma35_gpiolib_register(struct platform_device *pdev, struct ma35_pinct
return 0;
}
+static void ma35_bank_iounmap(void *data)
+{
+ struct ma35_pin_bank *bank = data;
+
+ iounmap(bank->reg_base);
+ bank->reg_base = NULL;
+}
+
+static void ma35_bank_clk_release(void *data)
+{
+ struct ma35_pin_bank *bank = data;
+
+ clk_disable_unprepare(bank->clk);
+ clk_put(bank->clk);
+}
+
static int ma35_get_bank_data(struct ma35_pin_bank *bank)
{
int ret;
@@ -563,6 +580,10 @@ static int ma35_get_bank_data(struct ma35_pin_bank *bank)
if (!bank->reg_base)
return -ENOMEM;
+ ret = devm_add_action_or_reset(bank->dev, ma35_bank_iounmap, bank);
+ if (ret)
+ return ret;
+
bank->irq = fwnode_irq_get(bank->fwnode, 0);
bank->nr_pins = MA35_GPIO_PORT_MAX;
@@ -572,10 +593,12 @@ static int ma35_get_bank_data(struct ma35_pin_bank *bank)
return PTR_ERR(bank->clk);
ret = clk_prepare_enable(bank->clk);
- if (ret)
+ if (ret) {
clk_put(bank->clk);
+ return ret;
+ }
- return ret;
+ return devm_add_action_or_reset(bank->dev, ma35_bank_clk_release, bank);
}
static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_device *pdev)
@@ -583,7 +606,7 @@ static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_
struct fwnode_handle *child;
struct ma35_pin_ctrl *ctrl;
struct ma35_pin_bank *bank;
- int i, id = 0;
+ int i, id = 0, ret;
ctrl = pctl->ctrl;
ctrl->nr_banks = MA35_GPIO_BANK_MAX;
@@ -603,8 +626,12 @@ static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_
bank->fwnode = child;
bank->regmap = pctl->regmap;
bank->dev = &pdev->dev;
- if (!ma35_get_bank_data(bank))
- bank->valid = true;
+ ret = ma35_get_bank_data(bank);
+ if (ret) {
+ fwnode_handle_put(child);
+ return ret;
+ }
+ bank->valid = true;
id++;
}
return 0;
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-19 20:50 UTC|newest]
Thread overview: 10+ 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 ` Lee Jones [this message]
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 ` [PATCH v2 05/12] pinctrl: nuvoton: ma35: Avoid leaking map when parent node is missing 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 20:49 ` [PATCH v2 10/12] pinctrl: single: Free pinconf settings array in pcs_dt_free_map() Lee Jones
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-2-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