2021-08-12 11:03:23

by Evgeny Novikov

[permalink] [raw]
Subject: [PATCH] mtd: rawnand: intel: Fix error handling in probe

ebu_nand_probe() did not invoke ebu_dma_cleanup() and
clk_disable_unprepare() on some error handling paths. The patch fixes
that.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <[email protected]>
Co-developed-by: Kirill Shilimanov <[email protected]>
Signed-off-by: Kirill Shilimanov <[email protected]>
Co-developed-by: Anton Vasilyev <[email protected]>
Signed-off-by: Anton Vasilyev <[email protected]>
---
drivers/mtd/nand/raw/intel-nand-controller.c | 27 +++++++++++++-------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 8b49fd56cf96..29e8a546dcd6 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -631,19 +631,26 @@ static int ebu_nand_probe(struct platform_device *pdev)
ebu_host->clk_rate = clk_get_rate(ebu_host->clk);

ebu_host->dma_tx = dma_request_chan(dev, "tx");
- if (IS_ERR(ebu_host->dma_tx))
- return dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx),
- "failed to request DMA tx chan!.\n");
+ if (IS_ERR(ebu_host->dma_tx)) {
+ ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx),
+ "failed to request DMA tx chan!.\n");
+ goto err_disable_unprepare_clk;
+ }

ebu_host->dma_rx = dma_request_chan(dev, "rx");
- if (IS_ERR(ebu_host->dma_rx))
- return dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx),
- "failed to request DMA rx chan!.\n");
+ if (IS_ERR(ebu_host->dma_rx)) {
+ ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx),
+ "failed to request DMA rx chan!.\n");
+ ebu_host->dma_rx = NULL;
+ goto err_cleanup_dma;
+ }

resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs);
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
- if (!res)
- return -EINVAL;
+ if (!res) {
+ ret = -EINVAL;
+ goto err_cleanup_dma;
+ }
ebu_host->cs[cs].addr_sel = res->start;
writel(ebu_host->cs[cs].addr_sel | EBU_ADDR_MASK(5) | EBU_ADDR_SEL_REGEN,
ebu_host->ebu + EBU_ADDR_SEL(cs));
@@ -653,7 +660,8 @@ static int ebu_nand_probe(struct platform_device *pdev)
mtd = nand_to_mtd(&ebu_host->chip);
if (!mtd->name) {
dev_err(ebu_host->dev, "NAND label property is mandatory\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_cleanup_dma;
}

mtd->dev.parent = dev;
@@ -681,6 +689,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
nand_cleanup(&ebu_host->chip);
err_cleanup_dma:
ebu_dma_cleanup(ebu_host);
+err_disable_unprepare_clk:
clk_disable_unprepare(ebu_host->clk);

return ret;
--
2.26.2


2021-08-16 07:52:52

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH] mtd: rawnand: intel: Fix error handling in probe

Hi Evgeny,

Evgeny Novikov <[email protected]> wrote on Thu, 12 Aug 2021 14:01:00
+0300:

> ebu_nand_probe() did not invoke ebu_dma_cleanup() and
> clk_disable_unprepare() on some error handling paths. The patch fixes
> that.
>
> Found by Linux Driver Verification project (linuxtesting.org).

LGTM

Can you add a Fixes: tag and possibly a Cc: stable tag as well?
(same for "mtd: rawnand: mxic: Enable and prepare clocks in probe")

>
> Signed-off-by: Evgeny Novikov <[email protected]>
> Co-developed-by: Kirill Shilimanov <[email protected]>
> Signed-off-by: Kirill Shilimanov <[email protected]>
> Co-developed-by: Anton Vasilyev <[email protected]>
> Signed-off-by: Anton Vasilyev <[email protected]>
> ---
> drivers/mtd/nand/raw/intel-nand-controller.c | 27 +++++++++++++-------
> 1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
> index 8b49fd56cf96..29e8a546dcd6 100644
> --- a/drivers/mtd/nand/raw/intel-nand-controller.c
> +++ b/drivers/mtd/nand/raw/intel-nand-controller.c
> @@ -631,19 +631,26 @@ static int ebu_nand_probe(struct platform_device *pdev)
> ebu_host->clk_rate = clk_get_rate(ebu_host->clk);
>
> ebu_host->dma_tx = dma_request_chan(dev, "tx");
> - if (IS_ERR(ebu_host->dma_tx))
> - return dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx),
> - "failed to request DMA tx chan!.\n");
> + if (IS_ERR(ebu_host->dma_tx)) {
> + ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx),
> + "failed to request DMA tx chan!.\n");
> + goto err_disable_unprepare_clk;
> + }
>
> ebu_host->dma_rx = dma_request_chan(dev, "rx");
> - if (IS_ERR(ebu_host->dma_rx))
> - return dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx),
> - "failed to request DMA rx chan!.\n");
> + if (IS_ERR(ebu_host->dma_rx)) {
> + ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx),
> + "failed to request DMA rx chan!.\n");
> + ebu_host->dma_rx = NULL;
> + goto err_cleanup_dma;
> + }
>
> resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs);
> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
> - if (!res)
> - return -EINVAL;
> + if (!res) {
> + ret = -EINVAL;
> + goto err_cleanup_dma;
> + }
> ebu_host->cs[cs].addr_sel = res->start;
> writel(ebu_host->cs[cs].addr_sel | EBU_ADDR_MASK(5) | EBU_ADDR_SEL_REGEN,
> ebu_host->ebu + EBU_ADDR_SEL(cs));
> @@ -653,7 +660,8 @@ static int ebu_nand_probe(struct platform_device *pdev)
> mtd = nand_to_mtd(&ebu_host->chip);
> if (!mtd->name) {
> dev_err(ebu_host->dev, "NAND label property is mandatory\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err_cleanup_dma;
> }
>
> mtd->dev.parent = dev;
> @@ -681,6 +689,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
> nand_cleanup(&ebu_host->chip);
> err_cleanup_dma:
> ebu_dma_cleanup(ebu_host);
> +err_disable_unprepare_clk:
> clk_disable_unprepare(ebu_host->clk);
>
> return ret;

Thanks,
Miquèl