]> git.itanic.dy.fi Git - linux-stable/commitdiff
mtd: rawnand: intel: fix possible null-ptr-deref in ebu_nand_probe()
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 26 Apr 2022 08:49:12 +0000 (16:49 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Wed, 27 Apr 2022 15:15:07 +0000 (17:15 +0200)
It will cause null-ptr-deref when using 'res', if platform_get_resource()
returns NULL, so move using 'res' after devm_ioremap_resource() that
will check it to avoid null-ptr-deref.

Fixes: 0b1039f016e8 ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220426084913.4021868-2-yangyingliang@huawei.com
drivers/mtd/nand/raw/intel-nand-controller.c

index 7c1c80dae826aab0efb9b02517f85bba157eb21e..e91b879b32bdb78ef28c11301149299d88924607 100644 (file)
@@ -619,9 +619,9 @@ static int ebu_nand_probe(struct platform_device *pdev)
        resname = devm_kasprintf(dev, GFP_KERNEL, "nand_cs%d", cs);
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
        ebu_host->cs[cs].chipaddr = devm_ioremap_resource(dev, res);
-       ebu_host->cs[cs].nand_pa = res->start;
        if (IS_ERR(ebu_host->cs[cs].chipaddr))
                return PTR_ERR(ebu_host->cs[cs].chipaddr);
+       ebu_host->cs[cs].nand_pa = res->start;
 
        ebu_host->clk = devm_clk_get(dev, NULL);
        if (IS_ERR(ebu_host->clk))