提交 0415f4f9 编写于 作者: Y Yang Yingliang 提交者: Zheng Zengkai

mtd: rawnand: cadence: fix possible null-ptr-deref in cadence_nand_dt_probe()

stable inclusion
from stable-v5.10.121
commit 81f1ddffdc22ca5789e33b9d4712914e302090c1
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6CQ

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=81f1ddffdc22ca5789e33b9d4712914e302090c1

--------------------------------

[ Upstream commit a28ed09d ]

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: ec4ba01e ("mtd: rawnand: Add new Cadence NAND driver to MTD subsystem")
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220426084913.4021868-1-yangyingliang@huawei.comSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 d9407399
...@@ -2983,11 +2983,10 @@ static int cadence_nand_dt_probe(struct platform_device *ofdev) ...@@ -2983,11 +2983,10 @@ static int cadence_nand_dt_probe(struct platform_device *ofdev)
if (IS_ERR(cdns_ctrl->reg)) if (IS_ERR(cdns_ctrl->reg))
return PTR_ERR(cdns_ctrl->reg); return PTR_ERR(cdns_ctrl->reg);
res = platform_get_resource(ofdev, IORESOURCE_MEM, 1); cdns_ctrl->io.virt = devm_platform_get_and_ioremap_resource(ofdev, 1, &res);
cdns_ctrl->io.dma = res->start;
cdns_ctrl->io.virt = devm_ioremap_resource(&ofdev->dev, res);
if (IS_ERR(cdns_ctrl->io.virt)) if (IS_ERR(cdns_ctrl->io.virt))
return PTR_ERR(cdns_ctrl->io.virt); return PTR_ERR(cdns_ctrl->io.virt);
cdns_ctrl->io.dma = res->start;
dt->clk = devm_clk_get(cdns_ctrl->dev, "nf_clk"); dt->clk = devm_clk_get(cdns_ctrl->dev, "nf_clk");
if (IS_ERR(dt->clk)) if (IS_ERR(dt->clk))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册