From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Support Opensource <support.opensource@diasemi.com>,
Linus Walleij <linusw@kernel.org>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Laxman Dewangan <ldewangan@nvidia.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
Lee Jones <lee@kernel.org>, Joseph Chen <chenjh@rock-chips.com>,
Heiko Stuebner <heiko@sntech.de>,
Herve Codina <herve.codina@bootlin.com>,
Christophe Leroy <chleroy@kernel.org>,
David Rhodes <david.rhodes@cirrus.com>,
Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>,
Nikita Shubin <nikita.shubin@maquefel.me>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
Haotian Zhang <vulab@iscas.ac.cn>,
linux-gpio@vger.kernel.org, linux-sound@vger.kernel.org,
patches@opensource.cirrus.com, linux-kernel@vger.kernel.org
Subject: [PATCH 10/12] pinctrl: cirrus: cs42l43: Fix firmware node reference count underflow
Date: Fri, 04 Dec 2026 22:38:38 -0800 [thread overview]
Message-ID: <20261204-pinctrl-fwnode-fix-v1-10-8589cbd35fb2@gmail.com> (raw)
In-Reply-To: <20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com>
cs42l43_pin_probe() mishandles firmware node attachment and reference
counting across parent configurations. When an OF "pinctrl" child node
is present, commit 9b07cdf86a0b ("pinctrl: cirrus: Fix fwnode leak in
cs42l43_pin_probe()") drops the child reference via devres while the
platform device still holds it, causing platform_device_release() to
put it a second time (with a use-after-free in device_del() or
platform_device_release() if a dynamic OF node was freed early, while
unbinding without deleting the device leaves child->dev set). When an
OF parent lacks the optional "pinctrl" child node, that same commit
unintentionally falls back to attaching the parent codec node instead of
leaving the node unset as introduced by commit d5282a539297 ("pinctrl:
cs42l43: Add support for the cs42l43"). For non-OF parents,
device_set_node() attaches the parent MFD device's firmware node without
taking a reference, causing platform_device_release() to underflow its
reference count and prematurely tear down any attached software node.
Drop device_set_node() and supply the parent device's (or OF "pinctrl"
child's) firmware node via a per-instance pinctrl_desc.fwnode and
gpio_chip.fwnode instead. Look up only the "pinctrl" child node on OF
parents, leaving both fields NULL when it is absent, and release the
probe's firmware node reference when cs42l43_pin_probe() returns instead
of via devres, because pinctrl core and gpiolib (with the companion
gpiolib reference-counting fix) each hold their own reference. Because
pinctrl is registered before gpiochip, devres LIFO teardown also keeps
the node referenced through gpiochip_remove(). Also drop the manual
fwnode->dev assignment so gdev->dev (registered with gpio_chip.fwnode)
manages fw_devlink ownership and clears fwnode->dev on unbind without
violating fw_devlink invariants.
Fixes: d5282a539297 ("pinctrl: cs42l43: Add support for the cs42l43")
Fixes: 9b07cdf86a0b ("pinctrl: cirrus: Fix fwnode leak in cs42l43_pin_probe()")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 36 +++++++++++++-------------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
index a1c839b35557..97754e028118 100644
--- a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
+++ b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/string_choices.h>
@@ -31,6 +32,7 @@
struct cs42l43_pin {
struct gpio_chip gpio_chip;
+ struct pinctrl_desc pin_desc;
struct device *dev;
struct regmap *regmap;
@@ -530,9 +532,14 @@ static int cs42l43_gpio_add_pin_ranges(struct gpio_chip *chip)
return ret;
}
-static void cs42l43_fwnode_put(void *data)
+static struct fwnode_handle *cs42l43_pin_get_fwnode(struct device *parent)
{
- fwnode_handle_put(data);
+ struct fwnode_handle *fwnode = dev_fwnode(parent);
+
+ if (is_of_node(fwnode))
+ return fwnode_get_named_child_node(fwnode, "pinctrl");
+
+ return fwnode_handle_get(fwnode);
}
static int cs42l43_pin_probe(struct platform_device *pdev)
@@ -540,7 +547,6 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
struct cs42l43_pin *priv;
struct pinctrl_dev *pctldev;
- struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev);
int ret;
priv = devm_kzalloc_obj(&pdev->dev, *priv);
@@ -552,6 +558,8 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
priv->shutters_locked = cs42l43->hw_lock;
+ priv->pin_desc = cs42l43_pin_desc;
+
priv->gpio_chip.request = gpiochip_generic_request;
priv->gpio_chip.free = gpiochip_generic_free;
priv->gpio_chip.direction_input = pinctrl_gpio_direction_input;
@@ -565,30 +573,16 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
priv->gpio_chip.base = -1;
priv->gpio_chip.ngpio = CS42L43_NUM_GPIOS;
- if (is_of_node(fwnode)) {
- struct fwnode_handle *child;
-
- child = fwnode_get_named_child_node(fwnode, "pinctrl");
- if (child) {
- ret = devm_add_action_or_reset(&pdev->dev,
- cs42l43_fwnode_put, child);
- if (ret)
- return ret;
-
- if (!child->dev)
- child->dev = priv->dev;
- fwnode = child;
- }
- }
+ struct fwnode_handle *fwnode __free(fwnode_handle) =
+ cs42l43_pin_get_fwnode(cs42l43->dev);
+ priv->pin_desc.fwnode = fwnode;
priv->gpio_chip.fwnode = fwnode;
- device_set_node(priv->dev, fwnode);
-
devm_pm_runtime_enable(priv->dev);
pm_runtime_idle(priv->dev);
- pctldev = devm_pinctrl_register(priv->dev, &cs42l43_pin_desc, priv);
+ pctldev = devm_pinctrl_register(priv->dev, &priv->pin_desc, priv);
if (IS_ERR(pctldev))
return dev_err_probe(priv->dev, PTR_ERR(pctldev),
"Failed to register pinctrl\n");
--
2.56.1.987.g2ec0ab4260-goog
next prev parent reply other threads:[~2026-12-05 6:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 01/12] pinctrl: devicetree: Factor out dt_find_controller() helper Dmitry Torokhov
2026-12-05 12:01 ` Andy Shevchenko
2026-12-05 6:38 ` [PATCH 02/12] pinctrl: devicetree: Do not re-claim hogs for sibling devices Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc Dmitry Torokhov
2026-12-05 12:07 ` Andy Shevchenko
2026-12-05 6:38 ` [PATCH 04/12] pinctrl: da9062: Fix firmware node reference count underflow Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 05/12] pinctrl: as3722: " Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 06/12] pinctrl: max77620: " Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 07/12] pinctrl: madera: " Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 08/12] pinctrl: rk805: " Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 09/12] pinctrl: pef2256: " Dmitry Torokhov
2026-12-05 6:38 ` Dmitry Torokhov [this message]
2026-12-05 6:38 ` [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 12/12] pinctrl: ep93xx: " Dmitry Torokhov
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=20261204-pinctrl-fwnode-fix-v1-10-8589cbd35fb2@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@kernel.org \
--cc=chenjh@rock-chips.com \
--cc=chleroy@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=david.rhodes@cirrus.com \
--cc=heiko@sntech.de \
--cc=herve.codina@bootlin.com \
--cc=ldewangan@nvidia.com \
--cc=lee@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=nikita.shubin@maquefel.me \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
--cc=support.opensource@diasemi.com \
--cc=vulab@iscas.ac.cn \
/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®