From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796261745; b=W9GOFQ6/0ct9OAq7/AohK9E9fuURIrRA9lh19cdwEsHQHX6HM04LDY5tUA6/d0QyqxiR 2nN9KKLVrmJIFm5BGBMoaNHJ5rBpqD+eFaNSmOVxDruVzD58KmGCuJBRRj2YpzB4OL+8g Aj8f8vwp2g5RjaJuSlJ/eiJAr/hdomESasdH4+4LiJljOtBRed4q3boc+pXHzKE5fvTd1 UeGCuXVn5Oz0D6Kt1Aji8vicvd+gmr39SEQMJnx02/k/XafqYQkAsdCAwakuOdmuWzW/G mo2usakb0h8MBIlemc4SoJ2IIpzGDh0u4SA+DW2y2/WugkqzLZMzivRpLyNIiSEhbOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796261745; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Subject:Date:Message-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer; bh=1eCHTCdSl5/UN1ohzVRb2Qvx8AtvUeorVvMWUM6MLWs=; b=vU99nQc1Phc0/ZIstd2Eq1OyihvcSq8JN3oQg4i4yaa2Z1bk+Sa6aw7cJ4qwB5voGtso XpdLbLPmSEc4zU+Rdl0RmmpNRMnJBb382YXPDxp1D6+jN7ujgMoSea1Aru1572jY1k1nc 648pS3YA930WDvK24nz+P9/9Hs09a/6iw9Sg0Yx5q9CXXj+1OYBqM0xv5ERW++tbimOy+ 7wHEP75ee3xTPhmbhXN0X/0IYSiPFRcgbaozMfUfDtJm605wyauyY4MQzv5eAKMUxomHN VJHfLot01Pbyvvj0r9gLzvltxL5sV0RZEk22s1SebmVMWKIP8ausBeI6xLb4yevw4tQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="P/PsNcgP"; arc=none smtp.remote-ip=74.125.82.48 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6864B606A32D for ; Thu, 3 Dec 2026 01:35:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6864B606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=P/PsNcgP Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-1a3c08d6928so21324240c88.0 for ; Wed, 02 Dec 2026 17:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796261743; x=1796866543; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=1eCHTCdSl5/UN1ohzVRb2Qvx8AtvUeorVvMWUM6MLWs=; b=P/PsNcgPJ7E5yzRNNP4Y1keTW1mYRp4q2j4C/cfKM/B5snPtVB3kpllG0Pc/JySNJz XxtRoLWSNxDzqFRfOZe/EtnoTKkW6kZDtPVT3PCnp/NoKsGtraIVssDaKYQ9TTzcIzN1 /jUHLqjjmeUM8b46Vl1GjhSJz7Vk/XfRS6lMwBn6oGBNg+UL4LY5dfZ594g0YPZXDvcL GpnI8l9GcaJm9GfL1CSeessFtfZKTAnfpEUP3tajcb7VDNzRN5ZwT+Og4tDvHRNDkQ2z L3VERUGj2xaVRrK3C6z40uncvhVAmxi1FBb1EaiNgw/p6KHb86fjVkHrMp2+CfuZBxRK T5Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796261743; x=1796866543; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=1eCHTCdSl5/UN1ohzVRb2Qvx8AtvUeorVvMWUM6MLWs=; b=t4UVe9EPck/FCVbzMzx+ZD3syrkUQghrwmzw0/4vgK36Mo3Ke8ETg1u6xJrToRTTsA Gm6pzYSCAbIc30noCfKXk4WIGV8lluJSVNkknv+dhntDwA0NIpDr7Zx2ZaQ5Z7eSUfR+ nlAJpZYHMDkgpbrt0aIvOwtPSBEkOeLENri+uCj2/6fjFG/GAdh60UvzyYmjUUpuxH9o gjxAHl4jviu0VhHAddjNxB3dX0o570EkS4lbtcMP7qQJ3VIhlybPEjBJj7p8Ll5a+8DW vT4qPcbEc4wKpKop3ig5Lo58XzztnSScrAGJ8EKOYt2JoFuB1w/oozYTxMiohKi61GDq SuFw== X-Forwarded-Encrypted: i=1; AL+hErG4cgafMNhChdVa+rxhdy3fzVz5MocPh4bdWc0tfTXjGcPJh3AWZitZDHvR3eGWELDz946ejBpI5zFS3Rw=@vger.kernel.org X-Gm-Message-State: APuU4Z8VTMAoswZGB5IjHWRMN44W4yKbE6zW5sLEEiMnhsCMAoMKkHr/ 9ZnMMx7YnKQXWkckcD3Y6wN//DCl1qGh8FvtJ25l8/L6G/XVJqrIuFesU+EMYw== X-Gm-Gg: AZFdTZfIiMbRME0gDg3QGMhB0dS4HrBy2XfbUn6luRga/FM/srBmj3skWnJwYDXuImn 8P1Z9CU0vTFFqK8WVG3dKPG8j2Xz01oLTL2Z0BB4BciqtyeLYuzqqaCkaYYv0Qyx9V58PxIcaI3 VVFZ3kQtwbMmiR2FXFfzyCSovRRNqJElJAU9Z+l9Xf0tqzm4OUL8zJcq63/akX89d6NPB5I9W7W p0YdQ/NQZeb7Q6XtFfDfP21PdImA07J3ub/3Cq9esKdX1KJ3hYc/78v7XzNxpjRXsNlSUo0R4H9 5t/uI58YcmGm6MlwDkj2ainIp3SuPoGvwvBiJD010NhDAQ0NadfxpqYYauUX1TPu0LN8WFH1AU0 tieBJXkKCdg0dJocvBxI4SjekS8jOM8QpS1owXR4G2dfYPZR89DqIRevARCnQn9dbp1xYOGZADP jfkVpCbBtIGezj9YiXhbNjDhAJ9PHWi9Mm6nXd3pegWjcc8tbxRhqK6UninW917Q+EojZxgsZVV h7MY3xDIVrl+e9BbN7oSlgMPcxF+KRvUr0H3uD49pYXoZT6jWC+dUg6HSRqW382hRkNYQ6m8baM wR98odHIM+2/IaZKYI1+jSX2hV/s5Zl8bgXiMuqQ9rl5mTaBFUJxepKrqucfOeFe0ME67i4jLRs zC5CL23p8OdPB6b+2 X-Received: by 2002:a05:693c:41c3:20b0:387:cb1:2214 with SMTP id 5a478bee46e88-3870cb12290mr12098851eec.22.1796261743175; Wed, 02 Dec 2026 17:35:43 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:5b9e:6509:7a57:220]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38566cd46c5sm155432860eec.11.2026.12.02.17.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 17:35:42 -0800 (PST) From: Dmitry Torokhov Subject: [PATCH 0/3] driver core: swnode: fix release with shared primary fwnode Date: Wed, 02 Dec 2026 17:34:48 -0800 Message-Id: <20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIADnHEGsC/yXMQQ6CQAyF4auQrm3CjCNEr2JYVKZITRxIC4Ih3 N1Rl99L3r+BsQobXIoNlF9iMqQMdyig7SndGSVmgy995Xzp0JY0REbrSTniqPIkfWMnKxIFd+q OIdC5hvwflfP8a1+bv22+PbidvkHY9w9PbgONfQAAAA== X-Change-ID: 20261201-swnode-shared-primary-fix-aa415f344a97 To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: Johan Hovold , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Bartosz Golaszewski , driver-core@lists.linux.dev, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.17-dev 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 (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