Skip to contentSkip to conversation

x86/pmem: fix platform-device leak in error path

PATCH New Johan Hovold 1 participant 1 message Mar 3, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pmem: fix platform-device leak in error path

Make sure to free the platform device in the unlikely event that registration fails.

Fixes 7a67832c7e44 ("libnvdimm, e820: make CONFIG_X86_PMEM_LEGACY a tristate option")
---
 arch/x86/kernel/pmem.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/pmem.c +6 -1
index 6b07faaa1579..23154d24b117 100644
@@ -27,6 +27,11 @@ static __init int register_e820_pmem(void)
 	 * simply here to trigger the module to load on demand.
 	 */
 	pdev = platform_device_alloc("e820_pmem", -1);
-	return platform_device_add(pdev);
+
+	rc = platform_device_add(pdev);
+	if (rc)
+		platform_device_put(pdev);
+
+	return rc;
 }
 device_initcall(register_e820_pmem);
Signature · 1 line
2.34.1