From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: ldv-project@linuxtesting.org, Richard Weinberger <richard@nod.at>,
linux-kernel@vger.kernel.org, Stefan Agner <stefan@agner.ch>,
linux-mtd@lists.infradead.org
Subject: Re: [PATCH v3] mtd: nand: vf610: fix error handling in vf610_nfc_probe()
Date: Tue, 30 Jan 2018 14:11:41 +0100 [thread overview]
Message-ID: <20180130141141.7f4fd15a@bbrezillon> (raw)
In-Reply-To: <1517005961-7938-1-git-send-email-khoroshilov@ispras.ru>
On Sat, 27 Jan 2018 01:32:41 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:
> vf610_nfc_probe() misses error handling of mtd_device_register()
> and contains unneeded of_node_put() on error path.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted.
> v3: Rename error labels, remove of_node_put() per Boris Brezillon request.
Should be separated in 3 patches IMO:
1/ remove the unnecessary of_node_put()
2/ rename error label into err_disable_clk
3/ check mtd_device_register() return code
>
> drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++-------------
> 1 file changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
> index 8037d4b48a05..7cdc6eed305d 100644
> --- a/drivers/mtd/nand/vf610_nfc.c
> +++ b/drivers/mtd/nand/vf610_nfc.c
> @@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> dev_err(nfc->dev,
> "Only one NAND chip supported!\n");
> err = -EINVAL;
> - goto error;
> + goto err_disable_clk;
> }
>
> nand_set_flash_node(chip, child);
> @@ -692,7 +692,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (!nand_get_flash_node(chip)) {
> dev_err(nfc->dev, "NAND chip sub-node missing!\n");
> err = -ENODEV;
> - goto err_clk;
> + goto err_disable_clk;
> }
>
> chip->dev_ready = vf610_nfc_dev_ready;
> @@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd);
> if (err) {
> dev_err(nfc->dev, "Error requesting IRQ!\n");
> - goto error;
> + goto err_disable_clk;
> }
>
> vf610_nfc_preinit_controller(nfc);
> @@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* first scan to find the device and get the page size */
> err = nand_scan_ident(mtd, 1, NULL);
> if (err)
> - goto error;
> + goto err_disable_clk;
>
> vf610_nfc_init_controller(nfc);
>
> @@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) {
> dev_err(nfc->dev, "Unsupported flash page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> if (chip->ecc.mode == NAND_ECC_HW) {
> if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) {
> dev_err(nfc->dev, "Unsupported flash with hwecc\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> if (chip->ecc.size != mtd->writesize) {
> dev_err(nfc->dev, "Step size needs to be page size\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> /* Only 64 byte ECC layouts known */
> @@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> } else {
> dev_err(nfc->dev, "Unsupported ECC strength\n");
> err = -ENXIO;
> - goto error;
> + goto err_disable_clk;
> }
>
> chip->ecc.read_page = vf610_nfc_read_page;
> @@ -777,16 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> /* second phase scan */
> err = nand_scan_tail(mtd);
> if (err)
> - goto error;
> + goto err_disable_clk;
>
> platform_set_drvdata(pdev, mtd);
>
> /* Register device in MTD */
> - return mtd_device_register(mtd, NULL, 0);
> + err = mtd_device_register(mtd, NULL, 0);
> + if (err)
> + goto err_cleanup_nand;
> + return 0;
>
> -error:
> - of_node_put(nand_get_flash_node(chip));
> -err_clk:
> +err_cleanup_nand:
> + nand_cleanup(chip);
> +err_disable_clk:
> clk_disable_unprepare(nfc->clk);
> return err;
> }
next prev parent reply other threads:[~2018-01-30 13:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-22 21:43 [PATCH] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Alexey Khoroshilov
2017-12-22 21:57 ` Boris Brezillon
2017-12-23 19:18 ` [PATCH v2] " Alexey Khoroshilov
2018-01-06 9:12 ` Boris Brezillon
2018-01-06 9:25 ` Boris Brezillon
2018-01-26 22:32 ` [PATCH v3] " Alexey Khoroshilov
2018-01-30 13:11 ` Boris Brezillon [this message]
2018-02-09 22:28 ` [PATCH v4 0/3] " Alexey Khoroshilov
2018-02-09 22:28 ` [PATCH v4 1/3] mtd: nand: vf610: remove the unnecessary of_node_put() Alexey Khoroshilov
2018-02-09 22:28 ` [PATCH v4 2/3] mtd: nand: vf610: improve readability of error label Alexey Khoroshilov
2018-02-09 22:28 ` [PATCH v4 3/3] mtd: nand: vf610: check mtd_device_register() return code Alexey Khoroshilov
2018-02-10 9:43 ` Stefan Agner
2018-02-12 21:31 ` [PATCH v4 0/3] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180130141141.7f4fd15a@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=stefan@agner.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).