x86/pmem: fix platform-device leak in error path
PATCH RESEND 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")
Signed-off-by Johan Hovold <[email protected]>
---
It's been almost four months so resending.
Obviously not an important fix in itself, but this allows for getting rid of the last two users of platform_device_add() that failed to release the platform device on errors (and may help prevent new ones from being added).
Johan
arch/x86/kernel/pmem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/pmem.c +6 -1
@@ -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.35.1
[tip: x86/misc] x86/pmem: Fix platform-device leak in error path
The following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: 229e73d46994f15314f58b2d39bf952111d89193 Gitweb: https://git.kernel.org/tip/229e73d46994f15314f58b2d39bf952111d89193 Author: Johan Hovold <[email protected]> AuthorDate: Mon, 20 Jun 2022 16:07:23 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Jun 2022 18:01:16 +02:00
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 <[email protected]>
Signed-off-by Borislav Petkov <[email protected]>
--- arch/x86/kernel/pmem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/pmem.c +6 -1
@@ -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);