Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Johan Hovold and committed by
Borislav Petkov
229e73d4 a111daf0

+6 -1
+6 -1
arch/x86/kernel/pmem.c
··· 27 27 * simply here to trigger the module to load on demand. 28 28 */ 29 29 pdev = platform_device_alloc("e820_pmem", -1); 30 - return platform_device_add(pdev); 30 + 31 + rc = platform_device_add(pdev); 32 + if (rc) 33 + platform_device_put(pdev); 34 + 35 + return rc; 31 36 } 32 37 device_initcall(register_e820_pmem);