Linux ACPI
 help / color / mirror / Atom feed
* [PATCH 0/3] driver core: swnode: fix release with shared primary fwnode
@ 2026-12-03  1:34 Dmitry Torokhov
  2026-12-03  1:34 ` [PATCH 1/3] driver core: swnode: only release owned secondary software nodes Dmitry Torokhov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2026-12-03  1:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
  Cc: Johan Hovold, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, driver-core, linux-acpi,
	linux-kernel, stable

This series fixes secondary software node reference count corruption
and premature detachment when a child device shares its parent's
primary firmware node that has a secondary software node attached,
causing reference count underflow and use-after-free in the ACPI case
or early detachment and a leaked reference and sysfs link in the
non-ACPI case.

The issue came up while converting Windows ACPI GPIO lookups in
drivers/mfd/arizona-spi.c to a secondary software node, and also
affects existing ACPI MFD parents sharing their companion fwnode with
child platform devices such as
drivers/platform/x86/x86-android-tablets/lenovo.c.

When an ACPI-shared primary firmware node is detached from a child via
set_primary_fwnode(..., NULL), the child's firmware node pointer is
still left pointing to the parent's secondary software node, and
platform_device_release() drops an extra reference per child via
device_remove_software_node() or fwnode_handle_put(). When a non-ACPI
shared primary node stays attached through release,
device_remove_software_node() unconditionally clears the shared
secondary link and drops one of the parent's references, leaving the
other reference and sysfs link leaked.

The first patch adds a per-device flag tracking whether the device
attached a secondary software node, uses it in set_primary_fwnode() to
avoid leaving a shared primary node's secondary node on the child or
modifying the secondary link unless owned by the device, and gates
secondary software node removal and managed creation reference release
on that flag.

The second patch replaces the un-refcounted owner pointer in struct
swnode with a managed bitfield now that per-device ownership is tracked
via the new device flag.

The third patch adds KUnit regression tests covering shared primary
fwnodes with unmanaged and managed secondary software nodes, detachment
before release, child-owned secondary nodes on shared primary fwnodes,
release of unregistered devices with managed software nodes, and
device_remove_software_node() on a registered managed device.

This series is intentionally kept minimal for stable backporting.
Storing the secondary pointer directly on the shared struct
fwnode_handle still leaves broader limitations unaddressed:
set_primary_fwnode() only detects direct parent sharing (not grandparent
or sibling sharing), parent and child or sibling devices sharing a
primary node still contend for a single secondary slot, and cross-device
lookups of fwnode->secondary are not synchronized against concurrent
removal. A separate follow-up (such as an immutable composite
fwnode_handle) would be needed to address those cleanly.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Dmitry Torokhov (3):
      driver core: swnode: only release owned secondary software nodes
      software node: replace owner pointer with managed bitfield
      driver core: platform: tests: add shared primary fwnode swnode tests

 drivers/base/core.c                      |  15 +-
 drivers/base/swnode.c                    |  19 +-
 drivers/base/test/platform-device-test.c | 328 +++++++++++++++++++++++++++++++
 include/linux/device.h                   |   7 +
 4 files changed, 358 insertions(+), 11 deletions(-)
---
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
change-id: 20261201-swnode-shared-primary-fix-aa415f344a97

Thanks.

-- 
Dmitry


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03  1:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  1:34 [PATCH 0/3] driver core: swnode: fix release with shared primary fwnode Dmitry Torokhov
2026-12-03  1:34 ` [PATCH 1/3] driver core: swnode: only release owned secondary software nodes Dmitry Torokhov
2026-12-03  1:34 ` [PATCH 2/3] software node: replace owner pointer with managed bitfield Dmitry Torokhov
2026-12-03  1:34 ` [PATCH 3/3] driver core: platform: tests: add shared primary fwnode swnode tests Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox