Skip to contentSkip to conversation

driver core: platform: fix fwnode leak on registration failure

PATCH Applied Johan Hovold 3 participants 3 messages Nov 2

Subsystems (2)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/1 driver core: platform: fix fwnode leak on registration failure

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 Bartosz Golaszewski <[email protected]>
---
 drivers/base/platform.c | 1 -
 1 file changed, 1 deletion(-)
drivers/base/platform.c +0 -1
index 3593d45f4a7a..979593e5cca1 100644
@@ -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);
 	}
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Johan Hovold

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.

Quoted 7 lines

This issue was flagged by an LLM.

Fixes 7b5b51b2b05c ("driver core: platform: count references to all kinds of firmware nodes")
Cc Bartosz Golaszewski <[email protected]>

---

maintainer Applied
#2 lore raw
In reply to Johan Hovold
Quoted 1 line · Johan Hovold

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

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

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

      commit: 7b4c25424cf5

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.