memory: jz4780_nemc: Fix potential NULL dereference in jz4780_nemc_probe()
authorZhang Changzhong <zhangchangzhong@huawei.com>
Fri, 4 Dec 2020 08:31:57 +0000 (16:31 +0800)
committerKrzysztof Kozlowski <krzk@kernel.org>
Sat, 5 Dec 2020 13:57:52 +0000 (14:57 +0100)
platform_get_resource() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference
a bit later in the code.

This is detected by Coccinelle semantic patch.

Fixes: 911a88829725 ("memory: jz4780-nemc: driver for the NEMC on JZ4780 SoCs")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Acked-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/1607070717-32880-1-git-send-email-zhangchangzhong@huawei.com
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
drivers/memory/jz4780-nemc.c

index 608ae925e6414dde3a4ff1295ec4ee5ecedf4366..555f7ac3b7dd9ff4a98f66f1ebf3e95c14ccc9ba 100644 (file)
@@ -291,6 +291,8 @@ static int jz4780_nemc_probe(struct platform_device *pdev)
        nemc->dev = dev;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -EINVAL;
 
        /*
         * The driver currently only uses the registers up to offset