* [PATCH 00/12] pinctrl: Fix firmware node reference count underflows
@ 2026-12-05 6:38 Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 01/12] pinctrl: devicetree: Factor out dt_find_controller() helper Dmitry Torokhov
` (11 more replies)
0 siblings, 12 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
Several pinctrl drivers for MFD or auxiliary sub-devices call
device_set_node() or device_set_of_node_from_dev() during probe to
attach a parent or child firmware node onto their registered device.
Doing so mutates dev->fwnode or dev->of_node concurrently with sysfs
readers such as uevent_show() and causes firmware node reference count
underflows, out-of-sync OF/fwnode pointers (as in pinctrl-max7360, which
also risks secondary software node underflows), or premature software
node teardown when platform_device_release() runs. In addition,
pinctrl-da9062 overwrites an MFD_CELL_OF child DT node without dropping
its reference, and pinctrl-cs42l43 drops an OF "pinctrl" child reference
via devres while the device still holds it (causing a double-put and
potential UAF on dynamic OF nodes) while also falling back to the parent
codec OF node when the optional child is absent.
First factor out DT controller scanning into dt_find_controller() and
fix non-hog DT lookups so sibling devices sharing a controller's DT node
do not try to re-claim hogs via get_pinctrl_dev_from_of_node(). Then,
instead of mutating registered devices in probe, add an optional fwnode
field to struct pinctrl_desc (mirroring struct gpio_chip). Keep the
pinctrl core DT-agnostic by holding firmware node references in
struct pinctrl_dev and struct pinctrl, replacing
get_pinctrl_dev_from_of_node() with get_pinctrl_dev_from_fwnode(), and
releasing both references before freeing them on teardown.
Update all nine affected drivers in drivers/pinctrl/ to pass their
controller or GPIO chip firmware nodes directly via pinctrl_desc.fwnode
and gpio_chip.fwnode, leaving no device_set_node() or
device_set_of_node_from_dev() calls in drivers/pinctrl/. For
pinctrl-cs42l43, restore NULL when an OF parent lacks an optional
"pinctrl" child node, drop the manual fwnode->dev assignment so
gdev->dev manages fw_devlink ownership, and release its firmware node
reference when probe returns instead of via devres.
Dropping pinctrl-cs42l43's probe reference on return relies on the
companion patch "gpiolib: Hold firmware node reference for gpio_device
lifetime" so gdev->dev holds its own reference across device_del() and
for any userspace chardev lifetime (because pinctrl is registered first
in cs42l43, devres teardown keeps the node referenced by pinctrl core
until gpiochip_remove() returns). That gpiolib fix in turn depends on
"driver core: swnode: fix release with shared primary fwnode":
https://lore.kernel.org/lkml/20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com/
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Dmitry Torokhov (12):
pinctrl: devicetree: Factor out dt_find_controller() helper
pinctrl: devicetree: Do not re-claim hogs for sibling devices
pinctrl: Add optional fwnode to struct pinctrl_desc
pinctrl: da9062: Fix firmware node reference count underflow
pinctrl: as3722: Fix firmware node reference count underflow
pinctrl: max77620: Fix firmware node reference count underflow
pinctrl: madera: Fix firmware node reference count underflow
pinctrl: rk805: Fix firmware node reference count underflow
pinctrl: pef2256: Fix firmware node reference count underflow
pinctrl: cirrus: cs42l43: Fix firmware node reference count underflow
pinctrl: max7360: Pass parent fwnode via pinctrl_desc
pinctrl: ep93xx: Pass parent fwnode via pinctrl_desc
drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 36 +++++------
drivers/pinctrl/cirrus/pinctrl-madera-core.c | 3 +-
drivers/pinctrl/core.c | 18 ++++--
drivers/pinctrl/core.h | 10 ++-
drivers/pinctrl/devicetree.c | 91 ++++++++++++++--------------
drivers/pinctrl/pinctrl-as3722.c | 4 +-
drivers/pinctrl/pinctrl-da9062.c | 3 +-
drivers/pinctrl/pinctrl-ep93xx.c | 4 +-
drivers/pinctrl/pinctrl-max7360.c | 7 ++-
drivers/pinctrl/pinctrl-max77620.c | 3 +-
drivers/pinctrl/pinctrl-pef2256.c | 4 +-
drivers/pinctrl/pinctrl-rk805.c | 4 +-
include/linux/pinctrl/pinctrl.h | 5 ++
13 files changed, 102 insertions(+), 90 deletions(-)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261202-pinctrl-fwnode-fix-464463c3a7bf
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 01/12] pinctrl: devicetree: Factor out dt_find_controller() helper
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 02/12] pinctrl: devicetree: Do not re-claim hogs for sibling devices Dmitry Torokhov
` (10 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
Move the ancestor walk that locates the pin controller for a DT
configuration node out of dt_to_map_one_config() into a new
dt_find_controller() helper using __free(device_node) to manage the
device node reference across all exit paths. Return an ERR_PTR() on
lookup failure, NULL when skipping a self-referenced hog, or the matched
controller pointer, eliminating the magic return value of 1 between
dt_to_map_one_config() and pinctrl_dt_to_map().
No functional change intended.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/devicetree.c | 71 ++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 465b43092eb7..69e701cb9c1f 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -6,6 +6,7 @@
*/
#include <linux/device.h>
+#include <linux/err.h>
#include <linux/of.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/slab.h>
@@ -110,54 +111,57 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
}
EXPORT_SYMBOL_GPL(of_pinctrl_get);
-static int dt_to_map_one_config(struct pinctrl *p,
- struct pinctrl_dev *hog_pctldev,
- const char *statename,
- struct device_node *np_config)
+static struct pinctrl_dev *dt_find_controller(struct pinctrl *p,
+ struct pinctrl_dev *hog_pctldev,
+ struct device_node *np_config)
{
- struct pinctrl_dev *pctldev = NULL;
- struct device_node *np_pctldev;
- const struct pinctrl_ops *ops;
- int ret;
- struct pinctrl_map *map;
- unsigned int num_maps;
+ struct device_node *np_pctldev __free(device_node) = of_node_get(np_config);
+ struct pinctrl_dev *pctldev;
bool allow_default = false;
- /* Find the pin controller containing np_config */
- np_pctldev = of_node_get(np_config);
for (;;) {
if (!allow_default)
- allow_default = of_property_read_bool(np_pctldev,
- "pinctrl-use-default");
+ allow_default = of_property_read_bool(np_pctldev, "pinctrl-use-default");
np_pctldev = of_get_next_parent(np_pctldev);
if (!np_pctldev || of_node_is_root(np_pctldev)) {
- of_node_put(np_pctldev);
- ret = -ENODEV;
/* keep deferring if modules are enabled */
- if (IS_ENABLED(CONFIG_MODULES) && !allow_default && ret < 0)
- ret = -EPROBE_DEFER;
- return ret;
+ if (IS_ENABLED(CONFIG_MODULES) && !allow_default)
+ return ERR_PTR(-EPROBE_DEFER);
+ return ERR_PTR(-ENODEV);
}
/* If we're creating a hog we can use the passed pctldev */
- if (hog_pctldev && (np_pctldev == p->dev->of_node)) {
- pctldev = hog_pctldev;
- break;
- }
+ if (hog_pctldev && np_pctldev == p->dev->of_node)
+ return hog_pctldev;
pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
if (pctldev)
- break;
+ return pctldev;
/*
- * Do not defer probing of hogs (circular loop)
+ * Do not defer probing of hogs (circular loop).
*
- * Return 1 to let the caller catch the case.
+ * Return NULL to let the caller skip self-referenced configs.
*/
- if (np_pctldev == p->dev->of_node) {
- of_node_put(np_pctldev);
- return 1;
- }
+ if (np_pctldev == p->dev->of_node)
+ return NULL;
}
- of_node_put(np_pctldev);
+}
+
+static int dt_to_map_one_config(struct pinctrl *p,
+ struct pinctrl_dev *hog_pctldev,
+ const char *statename,
+ struct device_node *np_config)
+{
+ struct pinctrl_dev *pctldev;
+ const struct pinctrl_ops *ops;
+ int ret;
+ struct pinctrl_map *map;
+ unsigned int num_maps;
+
+ pctldev = dt_find_controller(p, hog_pctldev, np_config);
+ if (IS_ERR(pctldev))
+ return PTR_ERR(pctldev);
+ if (!pctldev)
+ return 0;
/*
* Call pinctrl driver to parse device tree node, and
@@ -270,11 +274,8 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
}
/* Parse the node */
- ret = dt_to_map_one_config(p, pctldev, statename,
- np_config);
+ ret = dt_to_map_one_config(p, pctldev, statename, np_config);
of_node_put(np_config);
- if (ret == 1)
- continue;
if (ret < 0)
goto err;
}
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 02/12] pinctrl: devicetree: Do not re-claim hogs for sibling devices
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 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc Dmitry Torokhov
` (9 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
Self-referenced pin configurations on a pin controller's DT node are
hogs claimed by pinctrl_claim_hogs() when the controller is enabled.
During non-hog lookups for a sibling device sharing that DT node (such
as a gpio_device registered on the same node), dt_find_controller()
previously called get_pinctrl_dev_from_of_node() before checking whether
np_pctldev matches the device's own node, causing it to find the already
registered controller and fail with -EINVAL when trying to re-claim the
hogs.
Lift hog policy out of dt_find_controller() by having it stop and
return NULL at the caller's own node before consulting
get_pinctrl_dev_from_of_node(). In dt_to_map_one_config(), consumer
lookups skip self-referenced configs, while hog claiming maps only
configs belonging to hog_pctldev instead of registering dead external
maps into pinctrl_maps.
Fixes: b2083062a3b4 ("pinctrl: do not defer device tree hogs")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/devicetree.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 69e701cb9c1f..f61a8c75e9e2 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -111,9 +111,8 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
}
EXPORT_SYMBOL_GPL(of_pinctrl_get);
-static struct pinctrl_dev *dt_find_controller(struct pinctrl *p,
- struct pinctrl_dev *hog_pctldev,
- struct device_node *np_config)
+static struct pinctrl_dev *dt_find_controller(struct device_node *np_config,
+ const struct device_node *stop_node)
{
struct device_node *np_pctldev __free(device_node) = of_node_get(np_config);
struct pinctrl_dev *pctldev;
@@ -130,19 +129,11 @@ static struct pinctrl_dev *dt_find_controller(struct pinctrl *p,
return ERR_PTR(-EPROBE_DEFER);
return ERR_PTR(-ENODEV);
}
- /* If we're creating a hog we can use the passed pctldev */
- if (hog_pctldev && np_pctldev == p->dev->of_node)
- return hog_pctldev;
+ if (np_pctldev == stop_node)
+ return NULL;
pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
if (pctldev)
return pctldev;
- /*
- * Do not defer probing of hogs (circular loop).
- *
- * Return NULL to let the caller skip self-referenced configs.
- */
- if (np_pctldev == p->dev->of_node)
- return NULL;
}
}
@@ -157,11 +148,23 @@ static int dt_to_map_one_config(struct pinctrl *p,
struct pinctrl_map *map;
unsigned int num_maps;
- pctldev = dt_find_controller(p, hog_pctldev, np_config);
+ pctldev = dt_find_controller(np_config, p->dev->of_node);
if (IS_ERR(pctldev))
return PTR_ERR(pctldev);
- if (!pctldev)
+ if (!pctldev) {
+ /*
+ * Self-referenced configs are hogs (or belong to an unregistered
+ * child controller). Use hog_pctldev during hog claiming
+ * (not on pinctrldev_list yet), or skip on normal lookups to
+ * avoid circular deferral and sibling re-claiming of hogs.
+ */
+ if (!hog_pctldev)
+ return 0;
+ pctldev = hog_pctldev;
+ } else if (hog_pctldev) {
+ /* Skip external controller configs while claiming hogs */
return 0;
+ }
/*
* Call pinctrl driver to parse device tree node, and
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc
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 6:38 ` [PATCH 02/12] pinctrl: devicetree: Do not re-claim hogs for sibling devices Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 04/12] pinctrl: da9062: Fix firmware node reference count underflow Dmitry Torokhov
` (8 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
Pin controller drivers for MFD or auxiliary sub-devices often need to
associate their controller with a parent or child firmware node for DT
lookups and hog parsing. Attaching that node directly to the live
device during probe mutates dev->fwnode and dev->of_node concurrently
with readers such as uevent_show() and leads to reference count
underflows, leaks, or rebind conflicts on release.
Add an optional fwnode field to struct pinctrl_desc so drivers can
supply a controller firmware node directly, mirroring struct gpio_chip.
Keep the pinctrl core DT-agnostic by holding firmware node references
in struct pinctrl_dev and struct pinctrl, replacing
get_pinctrl_dev_from_of_node() with get_pinctrl_dev_from_fwnode(), and
updating devicetree.c to convert between struct device_node and struct
fwnode_handle. Release both references before freeing the structs on
teardown.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/core.c | 18 ++++++++++++++----
drivers/pinctrl/core.h | 10 ++++++++--
drivers/pinctrl/devicetree.c | 19 +++++++------------
include/linux/pinctrl/pinctrl.h | 5 +++++
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 4968747a9650..df328ec5db25 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -21,6 +21,7 @@
#include <linux/init.h>
#include <linux/kref.h>
#include <linux/list.h>
+#include <linux/property.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
@@ -121,14 +122,17 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
return NULL;
}
-struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np)
+struct pinctrl_dev *get_pinctrl_dev_from_fwnode(const struct fwnode_handle *fwnode)
{
struct pinctrl_dev *pctldev;
+ if (!fwnode)
+ return NULL;
+
mutex_lock(&pinctrldev_list_mutex);
list_for_each_entry(pctldev, &pinctrldev_list, node)
- if (device_match_of_node(pctldev->dev, np)) {
+ if (pctldev->fwnode == fwnode) {
mutex_unlock(&pinctrldev_list_mutex);
return pctldev;
}
@@ -1111,11 +1115,13 @@ static struct pinctrl *create_pinctrl(struct device *dev,
if (!p)
return ERR_PTR(-ENOMEM);
p->dev = dev;
+ p->fwnode = fwnode_handle_get(pctldev ? pctldev->fwnode : dev_fwnode(dev));
INIT_LIST_HEAD(&p->states);
INIT_LIST_HEAD(&p->dt_maps);
ret = pinctrl_dt_to_map(p, pctldev);
if (ret < 0) {
+ fwnode_handle_put(p->fwnode);
kfree(p);
return ERR_PTR(ret);
}
@@ -1242,6 +1248,7 @@ static void pinctrl_free(struct pinctrl *p, bool inlist)
if (inlist)
list_del(&p->node);
+ fwnode_handle_put(p->fwnode);
kfree(p);
mutex_unlock(&pinctrl_list_mutex);
}
@@ -2157,6 +2164,7 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev,
INIT_LIST_HEAD(&pctldev->gpio_ranges);
INIT_LIST_HEAD(&pctldev->node);
pctldev->dev = dev;
+ pctldev->fwnode = fwnode_handle_get(pctldesc->fwnode ?: dev_fwnode(dev));
mutex_init(&pctldev->mutex);
/* check core ops for sanity */
@@ -2194,6 +2202,7 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev,
out_err:
mutex_destroy(&pctldev->mutex);
+ fwnode_handle_put(pctldev->fwnode);
kfree(pctldev);
return ERR_PTR(ret);
}
@@ -2201,9 +2210,9 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev,
static void pinctrl_uninit_controller(struct pinctrl_dev *pctldev,
const struct pinctrl_desc *pctldesc)
{
- pinctrl_free_pindescs(pctldev, pctldesc->pins,
- pctldesc->npins);
+ pinctrl_free_pindescs(pctldev, pctldesc->pins, pctldesc->npins);
mutex_destroy(&pctldev->mutex);
+ fwnode_handle_put(pctldev->fwnode);
kfree(pctldev);
}
@@ -2361,6 +2370,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)
mutex_unlock(&pctldev->mutex);
mutex_destroy(&pctldev->mutex);
+ fwnode_handle_put(pctldev->fwnode);
kfree(pctldev);
mutex_unlock(&pinctrldev_list_mutex);
}
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index fc513a9cdd4f..2ac402788463 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -18,7 +18,7 @@
struct dentry;
struct device;
-struct device_node;
+struct fwnode_handle;
struct module;
struct pinctrl;
@@ -40,6 +40,8 @@ struct pinctrl_state;
* @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
* ranges are added to this list at runtime
* @dev: the device entry for this pin controller
+ * @fwnode: firmware node for this pin controller; reference held until
+ * unregistration
* @owner: module providing the pin controller, used for refcounting
* @driver_data: driver data for drivers registering to the pin controller
* subsystem
@@ -63,6 +65,7 @@ struct pinctrl_dev {
#endif
struct list_head gpio_ranges;
struct device *dev;
+ struct fwnode_handle *fwnode;
struct module *owner;
void *driver_data;
struct pinctrl *p;
@@ -78,6 +81,8 @@ struct pinctrl_dev {
* struct pinctrl - per-device pin control state holder
* @node: global list node
* @dev: the device using this pin control handle
+ * @fwnode: firmware node for this handle; reference held for the handle's
+ * lifetime
* @states: a list of states for this device
* @state: the current state
* @dt_maps: the mapping table chunks dynamically parsed from device tree for
@@ -87,6 +92,7 @@ struct pinctrl_dev {
struct pinctrl {
struct list_head node;
struct device *dev;
+ struct fwnode_handle *fwnode;
struct list_head states;
struct pinctrl_state *state;
struct list_head dt_maps;
@@ -236,7 +242,7 @@ int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev,
#endif /* CONFIG_GENERIC_PINCTRL_GROUPS */
struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
-struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np);
+struct pinctrl_dev *get_pinctrl_dev_from_fwnode(const struct fwnode_handle *fwnode);
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned int pin);
int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index f61a8c75e9e2..ce7176636b68 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -59,8 +59,6 @@ void pinctrl_dt_free_maps(struct pinctrl *p)
dt_map->num_maps);
kfree(dt_map);
}
-
- of_node_put(p->dev->of_node);
}
static int dt_remember_or_free_map(struct pinctrl *p, const char *statename,
@@ -107,12 +105,12 @@ static int dt_remember_or_free_map(struct pinctrl *p, const char *statename,
struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
{
- return get_pinctrl_dev_from_of_node(np);
+ return get_pinctrl_dev_from_fwnode(of_fwnode_handle(np));
}
EXPORT_SYMBOL_GPL(of_pinctrl_get);
static struct pinctrl_dev *dt_find_controller(struct device_node *np_config,
- const struct device_node *stop_node)
+ const struct fwnode_handle *stop_fwnode)
{
struct device_node *np_pctldev __free(device_node) = of_node_get(np_config);
struct pinctrl_dev *pctldev;
@@ -129,9 +127,9 @@ static struct pinctrl_dev *dt_find_controller(struct device_node *np_config,
return ERR_PTR(-EPROBE_DEFER);
return ERR_PTR(-ENODEV);
}
- if (np_pctldev == stop_node)
+ if (of_fwnode_handle(np_pctldev) == stop_fwnode)
return NULL;
- pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
+ pctldev = get_pinctrl_dev_from_fwnode(of_fwnode_handle(np_pctldev));
if (pctldev)
return pctldev;
}
@@ -148,7 +146,7 @@ static int dt_to_map_one_config(struct pinctrl *p,
struct pinctrl_map *map;
unsigned int num_maps;
- pctldev = dt_find_controller(np_config, p->dev->of_node);
+ pctldev = dt_find_controller(np_config, p->fwnode);
if (IS_ERR(pctldev))
return PTR_ERR(pctldev);
if (!pctldev) {
@@ -210,7 +208,7 @@ static int dt_remember_dummy_state(struct pinctrl *p, const char *statename)
int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
{
- struct device_node *np = p->dev->of_node;
+ struct device_node *np = to_of_node(p->fwnode);
int state, ret;
char *propname;
struct property *prop;
@@ -220,7 +218,7 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
phandle phandle;
struct device_node *np_config;
- /* CONFIG_OF enabled, p->dev not instantiated from DT */
+ /* CONFIG_OF enabled, no DT node on device or pctldev->fwnode */
if (!np) {
if (of_have_populated_dt())
dev_dbg(p->dev,
@@ -228,9 +226,6 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
return 0;
}
- /* We may store pointers to property names within the node */
- of_node_get(np);
-
/* For each defined state ID */
for (state = 0; ; state++) {
/* Retrieve the pinctrl-* property */
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index c329cc693139..82689052c4c1 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -16,6 +16,7 @@
struct device;
struct device_node;
+struct fwnode_handle;
struct gpio_chip;
struct module;
struct seq_file;
@@ -143,6 +144,9 @@ struct pinctrl_ops {
* the hardware description
* @custom_conf_items: Information how to print @params in debugfs, must be
* the same size as the @custom_params, i.e. @num_custom_params
+ * @fwnode: Optional firmware node for the pin controller. If unset,
+ * the core falls back to the firmware node of the parent device.
+ * The core acquires its own reference to the node.
* @link_consumers: If true create a device link between pinctrl and its
* consumers (i.e. the devices requesting pin control states). This is
* sometimes necessary to ascertain the right suspend/resume order for
@@ -161,6 +165,7 @@ struct pinctrl_desc {
const struct pinconf_generic_params *custom_params;
const struct pin_config_item *custom_conf_items;
#endif
+ struct fwnode_handle *fwnode;
bool link_consumers;
};
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 04/12] pinctrl: da9062: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (2 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 05/12] pinctrl: as3722: " Dmitry Torokhov
` (7 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
da9062_pctl_probe() attaches the parent MFD device's firmware node to
the child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() drops a firmware node
reference and removes any attached software node, underflowing the
parent's reference count and prematurely tearing down a parent software
node. When MFD matches a "dlg,da9062-gpio" child DT node via
MFD_CELL_OF, overwriting the platform device's node also leaks that
child node's reference because mfd-core relies on
platform_device_release() to release it.
Since this driver only registers a GPIO chip and not a pin controller,
drop device_set_node() and pass the parent device's firmware node
directly via gpio_chip.fwnode while keeping the platform device as the
GPIO chip parent. Using gpio_chip.fwnode avoids mutating the registered
platform device during probe, preventing re-probe leaks and
platform_device_set_fwnode() warnings on software or secondary nodes.
Fixes: ce852837335a ("pinctrl: Propagate firmware node from a parent device")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-da9062.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-da9062.c b/drivers/pinctrl/pinctrl-da9062.c
index ab62b802bae3..40a2535dbb41 100644
--- a/drivers/pinctrl/pinctrl-da9062.c
+++ b/drivers/pinctrl/pinctrl-da9062.c
@@ -250,8 +250,6 @@ static int da9062_pctl_probe(struct platform_device *pdev)
struct da9062_pctl *pctl;
int i;
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
pctl = devm_kzalloc_obj(&pdev->dev, *pctl);
if (!pctl)
return -ENOMEM;
@@ -273,6 +271,7 @@ static int da9062_pctl_probe(struct platform_device *pdev)
pctl->gc = reference_gc;
pctl->gc.label = dev_name(&pdev->dev);
pctl->gc.parent = &pdev->dev;
+ pctl->gc.fwnode = dev_fwnode(parent);
platform_set_drvdata(pdev, pctl);
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 05/12] pinctrl: as3722: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (3 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 04/12] pinctrl: da9062: Fix firmware node reference count underflow Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 06/12] pinctrl: max77620: " Dmitry Torokhov
` (6 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
as3722_pinctrl_probe() attaches the parent MFD device's firmware node
to the child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() calls
device_remove_software_node() and fwnode_handle_put(), underflowing the
parent's reference count and prematurely tearing down a parent software
node.
Drop device_set_node() and pass the parent device's firmware node
directly via pinctrl_desc.fwnode and gpio_chip.fwnode instead of
mutating the registered platform device during probe.
Fixes: c8ce87820607 ("pincntrl: add support for ams AS3722 pin control driver")
Fixes: ce852837335a ("pinctrl: Propagate firmware node from a parent device")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-as3722.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-as3722.c b/drivers/pinctrl/pinctrl-as3722.c
index 08d1b55b014b..470d55b86072 100644
--- a/drivers/pinctrl/pinctrl-as3722.c
+++ b/drivers/pinctrl/pinctrl-as3722.c
@@ -542,8 +542,6 @@ static int as3722_pinctrl_probe(struct platform_device *pdev)
struct as3722_pctrl_info *as_pci;
int ret;
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
as_pci = devm_kzalloc_obj(&pdev->dev, *as_pci);
if (!as_pci)
return -ENOMEM;
@@ -558,6 +556,7 @@ static int as3722_pinctrl_probe(struct platform_device *pdev)
as_pci->pin_groups = as3722_pingroups;
as_pci->num_pin_groups = ARRAY_SIZE(as3722_pingroups);
as3722_pinctrl_desc.name = dev_name(&pdev->dev);
+ as3722_pinctrl_desc.fwnode = dev_fwnode(pdev->dev.parent);
as_pci->pctl = devm_pinctrl_register(&pdev->dev, &as3722_pinctrl_desc,
as_pci);
if (IS_ERR(as_pci->pctl)) {
@@ -567,6 +566,7 @@ static int as3722_pinctrl_probe(struct platform_device *pdev)
as_pci->gpio_chip = as3722_gpio_chip;
as_pci->gpio_chip.parent = &pdev->dev;
+ as_pci->gpio_chip.fwnode = dev_fwnode(pdev->dev.parent);
ret = devm_gpiochip_add_data(&pdev->dev, &as_pci->gpio_chip, as_pci);
if (ret < 0) {
dev_err(&pdev->dev, "Couldn't register gpiochip, %d\n", ret);
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 06/12] pinctrl: max77620: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (4 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 05/12] pinctrl: as3722: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:53 ` sashiko-bot
2026-12-05 6:38 ` [PATCH 07/12] pinctrl: madera: " Dmitry Torokhov
` (5 subsequent siblings)
11 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
max77620_pinctrl_probe() attaches the parent MFD device's firmware node
to the child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() calls
device_remove_software_node() and fwnode_handle_put(), underflowing the
parent's reference count and prematurely tearing down a parent software
node.
Drop device_set_node() and pass the parent device's firmware node
directly via pinctrl_desc.fwnode instead of mutating the registered
platform device during probe.
Fixes: 2df723d49cda ("pinctrl: max77620: add pincontrol driver for MAX77620/MAX20024")
Fixes: ce852837335a ("pinctrl: Propagate firmware node from a parent device")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-max77620.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-max77620.c b/drivers/pinctrl/pinctrl-max77620.c
index b181cde6d7c5..27e0fe9adcc9 100644
--- a/drivers/pinctrl/pinctrl-max77620.c
+++ b/drivers/pinctrl/pinctrl-max77620.c
@@ -554,8 +554,6 @@ static int max77620_pinctrl_probe(struct platform_device *pdev)
struct max77620_pctrl_info *mpci;
int i;
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
mpci = devm_kzalloc_obj(&pdev->dev, *mpci);
if (!mpci)
return -ENOMEM;
@@ -572,6 +570,7 @@ static int max77620_pinctrl_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, mpci);
max77620_pinctrl_desc.name = dev_name(&pdev->dev);
+ max77620_pinctrl_desc.fwnode = dev_fwnode(pdev->dev.parent);
for (i = 0; i < MAX77620_PIN_NUM; ++i) {
mpci->fps_config[i].active_fps_src = -1;
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 07/12] pinctrl: madera: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (5 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 06/12] pinctrl: max77620: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 08/12] pinctrl: rk805: " Dmitry Torokhov
` (4 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
madera_pin_probe() attaches the parent MFD device's firmware node to the
child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() calls
device_remove_software_node() and fwnode_handle_put(), underflowing the
parent's reference count and prematurely tearing down a parent software
node.
Drop device_set_node() and pass the parent device's firmware node
directly via pinctrl_desc.fwnode instead of mutating the registered
platform device during probe.
Fixes: 218d72a77b0b ("pinctrl: madera: Add driver for Cirrus Logic Madera codecs")
Fixes: ce852837335a ("pinctrl: Propagate firmware node from a parent device")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/cirrus/pinctrl-madera-core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
index 61a84e9b07ed..35624208a564 100644
--- a/drivers/pinctrl/cirrus/pinctrl-madera-core.c
+++ b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
@@ -1007,8 +1007,6 @@ static int madera_pin_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "%s\n", __func__);
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
priv = devm_kzalloc_obj(&pdev->dev, *priv);
if (!priv)
return -ENOMEM;
@@ -1049,6 +1047,7 @@ static int madera_pin_probe(struct platform_device *pdev)
return -ENODEV;
madera_pin_desc.npins = priv->chip->n_pins;
+ madera_pin_desc.fwnode = dev_fwnode(pdev->dev.parent);
ret = devm_pinctrl_register_and_init(&pdev->dev,
&madera_pin_desc,
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/12] pinctrl: rk805: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (6 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 07/12] pinctrl: madera: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 09/12] pinctrl: pef2256: " Dmitry Torokhov
` (3 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
rk805_pinctrl_probe() attaches the parent MFD device's firmware node to
the child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() calls
device_remove_software_node() and fwnode_handle_put(), underflowing the
parent's reference count and prematurely tearing down a parent software
node.
Drop device_set_node() and pass the parent device's firmware node
directly via pinctrl_desc.fwnode and gpio_chip.fwnode instead of
mutating the registered platform device during probe.
Fixes: ea479996c79b ("pinctrl: Add pinctrl driver for the RK805 PMIC")
Fixes: ce852837335a ("pinctrl: Propagate firmware node from a parent device")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-rk805.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-rk805.c b/drivers/pinctrl/pinctrl-rk805.c
index ff446e29ab0b..b704781c9a32 100644
--- a/drivers/pinctrl/pinctrl-rk805.c
+++ b/drivers/pinctrl/pinctrl-rk805.c
@@ -605,8 +605,6 @@ static int rk805_pinctrl_probe(struct platform_device *pdev)
struct rk805_pctrl_info *pci;
int ret;
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
pci = devm_kzalloc_obj(&pdev->dev, *pci);
if (!pci)
return -ENOMEM;
@@ -615,8 +613,10 @@ static int rk805_pinctrl_probe(struct platform_device *pdev)
pci->rk808 = dev_get_drvdata(pdev->dev.parent);
pci->pinctrl_desc = rk805_pinctrl_desc;
+ pci->pinctrl_desc.fwnode = dev_fwnode(pdev->dev.parent);
pci->gpio_chip = rk805_gpio_chip;
pci->gpio_chip.parent = &pdev->dev;
+ pci->gpio_chip.fwnode = dev_fwnode(pdev->dev.parent);
platform_set_drvdata(pdev, pci);
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/12] pinctrl: pef2256: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (7 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 08/12] pinctrl: rk805: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 10/12] pinctrl: cirrus: cs42l43: " Dmitry Torokhov
` (2 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
pef2256_pinctrl_probe() attaches the parent MFD device's firmware node
to the child platform device using device_set_node() without taking a
reference. On teardown, platform_device_release() calls
device_remove_software_node() and fwnode_handle_put(), underflowing the
parent's reference count and prematurely tearing down a parent software
node.
Drop device_set_node() and pass the parent device's firmware node
directly via pinctrl_desc.fwnode instead of mutating the registered
platform device during probe.
Fixes: 37c646dc515a ("pinctrl: Add support for the Lantic PEF2256 pinmux")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-pef2256.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-pef2256.c b/drivers/pinctrl/pinctrl-pef2256.c
index 70101e3757db..53e64b85dfaf 100644
--- a/drivers/pinctrl/pinctrl-pef2256.c
+++ b/drivers/pinctrl/pinctrl-pef2256.c
@@ -15,6 +15,7 @@
#include <linux/pinctrl/pinconf-generic.h>
#include <linux/pinctrl/pinmux.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/slab.h>
@@ -277,6 +278,7 @@ static int pef2256_register_pinctrl(struct pef2256_pinctrl *pef2256)
pef2256->pctrl_desc.owner = THIS_MODULE;
pef2256->pctrl_desc.pctlops = &pef2256_pctlops;
pef2256->pctrl_desc.pmxops = &pef2256_pmxops;
+ pef2256->pctrl_desc.fwnode = dev_fwnode(pef2256->dev->parent);
if (pef2256->version == PEF2256_VERSION_1_2) {
pef2256->pctrl_desc.pins = pef2256_v12_pins;
pef2256->pctrl_desc.npins = ARRAY_SIZE(pef2256_v12_pins);
@@ -327,8 +329,6 @@ static int pef2256_pinctrl_probe(struct platform_device *pdev)
if (!pef2256_pinctrl)
return -ENOMEM;
- device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
-
pef2256 = dev_get_drvdata(pdev->dev.parent);
pef2256_pinctrl->dev = &pdev->dev;
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 10/12] pinctrl: cirrus: cs42l43: Fix firmware node reference count underflow
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (8 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 09/12] pinctrl: pef2256: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
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
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (9 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 10/12] pinctrl: cirrus: cs42l43: " Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
2026-12-05 6:57 ` sashiko-bot
2026-12-05 6:38 ` [PATCH 12/12] pinctrl: ep93xx: " Dmitry Torokhov
11 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
max7360_pinctrl_probe() calls device_set_of_node_from_dev() to copy the
parent MFD device's OF node onto the child platform device. That
mutates a live registered platform device during probe and leaves
dev->of_node and dev->fwnode out of sync, which leaked the OF node
reference on kernels between commit 7b5b51b2b05c ("driver core:
platform: count references to all kinds of firmware nodes") and
commit ff4e64e69415 ("software node: ignore primary nodes in
device_remove_software_node()"), and underflows any secondary software
node attached to the parent OF node during platform_device_release().
Drop device_set_of_node_from_dev() and pass the parent device's firmware
node directly via pinctrl_desc.fwnode.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-max7360.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-max7360.c b/drivers/pinctrl/pinctrl-max7360.c
index fdf2ac8276af..dd2ad55b78c6 100644
--- a/drivers/pinctrl/pinctrl-max7360.c
+++ b/drivers/pinctrl/pinctrl-max7360.c
@@ -14,6 +14,7 @@
#include <linux/mfd/max7360.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/stddef.h>
@@ -190,10 +191,10 @@ static int max7360_pinctrl_probe(struct platform_device *pdev)
* This MFD sub-device does not have any associated device tree node:
* properties are stored in the device node of the parent (MFD) device
* and this same node is used in phandles of client devices.
- * Reuse this device tree node here, as otherwise the pinctrl subsystem
- * would be confused by this topology.
+ * Pass this firmware node to the pinctrl core, as otherwise the
+ * pinctrl subsystem would be confused by this topology.
*/
- device_set_of_node_from_dev(dev, dev->parent);
+ pd->fwnode = dev_fwnode(dev->parent);
chip->pctldev = devm_pinctrl_register(dev, pd, chip);
if (IS_ERR(chip->pctldev))
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 12/12] pinctrl: ep93xx: Pass parent fwnode via pinctrl_desc
2026-12-05 6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
` (10 preceding siblings ...)
2026-12-05 6:38 ` [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc Dmitry Torokhov
@ 2026-12-05 6:38 ` Dmitry Torokhov
11 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2026-12-05 6:38 UTC (permalink / raw)
To: Support Opensource, Linus Walleij, Charles Keepax,
Andy Shevchenko, Laxman Dewangan, Richard Fitzgerald, Lee Jones,
Joseph Chen, Heiko Stuebner, Herve Codina, Christophe Leroy,
David Rhodes, Mathieu Dubois-Briand, Nikita Shubin
Cc: Bartosz Golaszewski, Haotian Zhang, linux-gpio, linux-sound,
patches, linux-kernel
ep93xx_pmx_probe() calls device_set_node() to copy the parent device's
firmware node onto the auxiliary device so
get_pinctrl_dev_from_fwnode() can match it.
Drop device_set_node() and supply the parent device's firmware node
directly via pinctrl_desc.fwnode instead of mutating the registered
auxiliary device during probe.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/pinctrl/pinctrl-ep93xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-ep93xx.c b/drivers/pinctrl/pinctrl-ep93xx.c
index b357aa2c138e..d21ae47bc857 100644
--- a/drivers/pinctrl/pinctrl-ep93xx.c
+++ b/drivers/pinctrl/pinctrl-ep93xx.c
@@ -1401,8 +1401,8 @@ static int ep93xx_pmx_probe(struct auxiliary_device *adev,
return dev_err_probe(dev, -EINVAL, "unknown pin control model: %u\n", pmx->model);
}
- /* using parent of_node to match in get_pinctrl_dev_from_of_node() */
- device_set_node(dev, dev_fwnode(adev->dev.parent));
+ /* Use parent fwnode to match in get_pinctrl_dev_from_fwnode() */
+ ep93xx_pmx_desc.fwnode = dev_fwnode(dev->parent);
pmx->pctl = devm_pinctrl_register(dev, &ep93xx_pmx_desc, pmx);
if (IS_ERR(pmx->pctl))
return dev_err_probe(dev, PTR_ERR(pmx->pctl), "could not register pinmux driver\n");
--
2.56.1.987.g2ec0ab4260-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 06/12] pinctrl: max77620: Fix firmware node reference count underflow
2026-12-05 6:38 ` [PATCH 06/12] pinctrl: max77620: " Dmitry Torokhov
@ 2026-12-05 6:53 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-05 6:53 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-gpio, linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] pinctrl: max77620: race on shared
max77620_pinctrl_desc.fwnode in probe
--
commit 8034ada881c8b38819a53fada36d048098ce2cf3
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
pinctrl: max77620: Fix firmware node reference count underflow
This patch drops device_set_node() from max77620_pinctrl_probe() and
instead passes the parent device's firmware node via
max77620_pinctrl_desc.fwnode.
> diff --git a/drivers/pinctrl/pinctrl-max77620.c b/drivers/pinctrl/pinctrl-max77620.c
> index b181cde6d7c5e..27e0fe9adcc92 100644
> --- a/drivers/pinctrl/pinctrl-max77620.c
> +++ b/drivers/pinctrl/pinctrl-max77620.c
[ ... ]
> @@ -572,6 +570,7 @@ static int max77620_pinctrl_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, mpci);
>
> max77620_pinctrl_desc.name = dev_name(&pdev->dev);
> + max77620_pinctrl_desc.fwnode = dev_fwnode(pdev->dev.parent);
[Severity: Medium]
Can concurrent probes race on max77620_pinctrl_desc.fwnode?
max77620_pinctrl_desc is a single file-scope static struct shared by all
instances bound to max77620_pinctrl_driver. Since both max77620-pinctrl
and max20024-pinctrl match this driver, two devices can probe in parallel
because the driver core only takes per-device locks:
CPU0 CPU1
max77620_pinctrl_probe(devA)
max77620_pinctrl_desc.fwnode = ...
devm_pinctrl_register()
pinctrl_init_controller()
kzalloc_obj(*pctldev)
max77620_pinctrl_probe(devB)
max77620_pinctrl_desc.fwnode = ...
fwnode_handle_get(...) <-- gets devB's parent fwnode
This causes devA's pin controller to bind devB's parent firmware node, or
trigger a use-after-free in fwnode_handle_get() if devB's parent is torn
down concurrently. Copying a const template into a per-instance
struct pinctrl_desc in struct max77620_pctrl_info would avoid this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com?part=6
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc
2026-12-05 6:38 ` [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc Dmitry Torokhov
@ 2026-12-05 6:57 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-05 6:57 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-gpio, linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] pinctrl: max7360: missing Fixes trailer for
max7360_pinctrl_probe() bug fix
--
commit 84ac91dd7a7b09628ca273e7cd8b6c558e59a762
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> pinctrl: max7360: Pass parent fwnode via pinctrl_desc
>
> max7360_pinctrl_probe() calls device_set_of_node_from_dev() to copy the
> parent MFD device's OF node onto the child platform device. That
> mutates a live registered platform device during probe and leaves
> dev->of_node and dev->fwnode out of sync, which leaked the OF node
> reference on kernels between commit 7b5b51b2b05c ("driver core:
> platform: count references to all kinds of firmware nodes") and
> commit ff4e64e69415 ("software node: ignore primary nodes in
> device_remove_software_node()"), and underflows any secondary software
> node attached to the parent OF node during platform_device_release().
>
> Drop device_set_of_node_from_dev() and pass the parent device's firmware
> node directly via pinctrl_desc.fwnode.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
[Severity: Low]
This looks like a bug fix for the device_set_of_node_from_dev() call in
max7360_pinctrl_probe(). Should this include:
Fixes: b4b993c0e394 ("pinctrl: Add MAX7360 pinctrl driver")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com?part=11
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-12-05 6:57 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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 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:53 ` sashiko-bot
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 ` [PATCH 10/12] pinctrl: cirrus: cs42l43: " Dmitry Torokhov
2026-12-05 6:38 ` [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc Dmitry Torokhov
2026-12-05 6:57 ` sashiko-bot
2026-12-05 6:38 ` [PATCH 12/12] pinctrl: ep93xx: " Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox