All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86/amd/hfi: fix platform device leak on init failure
@ 2026-09-21  8:26 Guangshuo Li
  2026-09-21 13:43 ` Mario Limonciello
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Guangshuo Li @ 2026-09-21  8:26 UTC (permalink / raw)
  To: Mario Limonciello, Perry Yuan, Hans de Goede, Ilpo Järvinen,
	Gautham R. Shenoy, Borislav Petkov (AMD), platform-driver-x86,
	linux-kernel
  Cc: Guangshuo Li, stable

amd_hfi_init() registers the HFI platform device before registering
the platform driver. If platform_driver_register() fails, the function
returns the error without unregistering the already registered platform
device.

Since the failed init path does not run amd_hfi_exit(), the platform
device remains registered and its reference is never dropped, preventing
the associated platform object from being released.

Unregister the platform device when platform driver registration fails
to properly unwind the successful device registration.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: 5d902ee5609a ("platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/platform/x86/amd/hfi/hfi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index e0ebcb0c4acd..449aad914ad1 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -530,8 +530,10 @@ static int __init amd_hfi_init(void)
 	}
 
 	ret = platform_driver_register(&amd_hfi_driver);
-	if (ret)
+	if (ret) {
 		pr_err("failed to register HFI driver\n");
+		platform_device_unregister(device);
+	}
 
 	return ret;
 }
-- 
2.43.0


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

end of thread, other threads:[~2026-10-09 10:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-21  8:26 [PATCH] platform/x86/amd/hfi: fix platform device leak on init failure Guangshuo Li
2026-09-21 13:43 ` Mario Limonciello
2026-09-21 17:29   ` Mario Limonciello
2026-09-21 15:04 ` krzk
2026-09-21 15:07 ` krzk
2026-09-21 15:15 ` krzk
2026-09-21 22:03   ` Krzysztof Kozlowski
2026-09-22  2:11     ` Guangshuo Li
2026-09-22  3:05       ` Borislav Petkov
2026-09-22  6:25         ` Guangshuo Li
2026-10-08 17:37 ` Ilpo Järvinen
2026-10-08 20:04   ` Mario Limonciello
2026-10-09 10:24     ` Ilpo Järvinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.