Skip to content

Commit a28ed09

Browse files
Yang Yingliangmiquelraynal
authored andcommitted
mtd: rawnand: cadence: fix possible null-ptr-deref in cadence_nand_dt_probe()
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. And use devm_platform_get_and_ioremap_resource() to simplify code. Fixes: ec4ba01 ("mtd: rawnand: Add new Cadence NAND driver to MTD subsystem") 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-1-yangyingliang@huawei.com
1 parent 3380557 commit a28ed09

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/mtd/nand/raw/cadence-nand-controller.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,11 +2983,10 @@ static int cadence_nand_dt_probe(struct platform_device *ofdev)
29832983
if (IS_ERR(cdns_ctrl->reg))
29842984
return PTR_ERR(cdns_ctrl->reg);
29852985

2986-
res = platform_get_resource(ofdev, IORESOURCE_MEM, 1);
2987-
cdns_ctrl->io.dma = res->start;
2988-
cdns_ctrl->io.virt = devm_ioremap_resource(&ofdev->dev, res);
2986+
cdns_ctrl->io.virt = devm_platform_get_and_ioremap_resource(ofdev, 1, &res);
29892987
if (IS_ERR(cdns_ctrl->io.virt))
29902988
return PTR_ERR(cdns_ctrl->io.virt);
2989+
cdns_ctrl->io.dma = res->start;
29912990

29922991
dt->clk = devm_clk_get(cdns_ctrl->dev, "nf_clk");
29932992
if (IS_ERR(dt->clk))

0 commit comments

Comments
 (0)