[PATCH] driver core: platform: fix fwnode leak on registration failure

From: Johan Hovold

Date: Mon Nov 02 2026 - 03:29:03 EST


A recent change started taking a reference also to non-OF firmware nodes
when registering platform devices.

The firmware node pointer is however still cleared on registration
failure when ACPI support is enabled, which means that the reference
leaks in platform_device_release() when the device is freed.

A software node also stays registered as device_remove_software_node()
returns early.

Drop the clearing of the fwnode pointer when registration fails to fix
the leak.

This issue was flagged by an LLM.

Fixes: 7b5b51b2b05c ("driver core: platform: count references to all kinds of firmware nodes")
Cc: stable@xxxxxxxxxxxxxxx # 7.3
Cc: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/base/platform.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 3593d45f4a7a..979593e5cca1 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -971,7 +971,6 @@ struct platform_device *platform_device_register_full(const struct platform_devi
ret = platform_device_add(pdev);
if (ret) {
err:
- ACPI_COMPANION_SET(&pdev->dev, NULL);
platform_device_put(pdev);
return ERR_PTR(ret);
}
--
2.55.0