]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/pmem: Check for platform_device_alloc() retval
authorLi Jun <lijun01@kylinos.cn>
Tue, 2 Jun 2026 10:07:11 +0000 (18:07 +0800)
committerBorislav Petkov (AMD) <bp@alien8.de>
Thu, 4 Jun 2026 15:31:56 +0000 (08:31 -0700)
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.

  [ bp: Massage commit message. ]

Signed-off-by: Li Jun <lijun01@kylinos.cn>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260602100711.2542568-1-lijun01@kylinos.cn
arch/x86/kernel/pmem.c

index 23154d24b1173df04b1731aa99779fd9f3931f83..04fb221716ff931cc9a7b0d3ef3951f8a3ad05a1 100644 (file)
@@ -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)