summaryrefslogtreecommitdiff
path: root/arch/x86/kernel/pmem.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2022-06-20 16:07:23 +0200
committerBorislav Petkov <bp@suse.de>2022-06-20 18:01:16 +0200
commit229e73d46994f15314f58b2d39bf952111d89193 (patch)
tree689f840a1e5e2e8bdf113bcaec0e6563813ba951 /arch/x86/kernel/pmem.c
parenta111daf0c53ae91e71fd2bfe7497862d14132e3e (diff)
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") Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20220620140723.9810-1-johan@kernel.org
Diffstat (limited to 'arch/x86/kernel/pmem.c')
-rw-r--r--arch/x86/kernel/pmem.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/arch/x86/kernel/pmem.c b/arch/x86/kernel/pmem.c
index 6b07faaa1579..23154d24b117 100644
--- a/arch/x86/kernel/pmem.c
+++ b/arch/x86/kernel/pmem.c
@@ -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);