Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [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

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