[PATCH] x86: pmem: Add NULL check for platform_device_alloc

From: Li Jun

Date: Tue Jun 02 2026 - 06:10:22 EST


Add proper error handling for the case when platform_device_alloc()
returns NULL due to memory allocation failure. This prevents a
potential NULL pointer dereference when trying to use the pdev pointer
without checking if allocation succeeded.

Signed-off-by: Li Jun <lijun01@xxxxxxxxxx>
---
arch/x86/kernel/pmem.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/pmem.c b/arch/x86/kernel/pmem.c
index 23154d24b117..04fb221716ff 100644
--- a/arch/x86/kernel/pmem.c
+++ b/arch/x86/kernel/pmem.c
@@ -27,6 +27,8 @@ static __init int register_e820_pmem(void)
* simply here to trigger the module to load on demand.
*/
pdev = platform_device_alloc("e820_pmem", -1);
+ if (!pdev)
+ return -ENOMEM;

rc = platform_device_add(pdev);
if (rc)
--
2.25.1