[PATCH] platform/x86/amd/hfi: fix platform device leak on init failure
From: Guangshuo Li
Date: Mon Sep 21 2026 - 04:26:28 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
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