public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	linux-mtd@lists.infradead.org, Kamal Dasu <kdasu.kdev@gmail.com>
Subject: Re: [PATCH v2 05/16] mtd: rawnand: docg4: fix the probe function error path
Date: Tue, 27 Mar 2018 09:59:28 +0200	[thread overview]
Message-ID: <20180327095928.5ff537af@bbrezillon> (raw)
In-Reply-To: <20180321130157.9524-6-miquel.raynal@bootlin.com>

On Wed, 21 Mar 2018 14:01:46 +0100
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> An error after nand_scan_tail() should trigger a nand_cleanup() call.
> The helper mtd_device_register() returns an error code that should
> be checked and nand_cleanup() called accordingly.

The commit message is not really describing what you're fixing here
because nand_cleanup() is called as part of nand_release().

How about something like that:

"
nand_release() should not be called on an MTD device that has not been
registered. While it should work thanks to the checks done in
mtd_device_unregister() it's a bad practice to cleanup/release
something that has not previously been initialized/allocated.
    
Rework the error path to follow this rule.
"

> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/mtd/nand/raw/docg4.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/docg4.c b/drivers/mtd/nand/raw/docg4.c
> index 1314aa99b9ab..bb96cb33cd6b 100644
> --- a/drivers/mtd/nand/raw/docg4.c
> +++ b/drivers/mtd/nand/raw/docg4.c
> @@ -1341,7 +1341,7 @@ static int __init probe_docg4(struct platform_device *pdev)
>  	nand = kzalloc(len, GFP_KERNEL);
>  	if (nand == NULL) {
>  		retval = -ENOMEM;
> -		goto fail_unmap;
> +		goto unmap;
>  	}
>  
>  	mtd = nand_to_mtd(nand);
> @@ -1357,7 +1357,7 @@ static int __init probe_docg4(struct platform_device *pdev)
>  	doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
>  	if (doc->bch == NULL) {
>  		retval = -EINVAL;
> -		goto fail;
> +		goto free_nand;
>  	}
>  
>  	platform_set_drvdata(pdev, doc);
> @@ -1366,30 +1366,32 @@ static int __init probe_docg4(struct platform_device *pdev)
>  	retval = read_id_reg(mtd);
>  	if (retval == -ENODEV) {
>  		dev_warn(dev, "No diskonchip G4 device found.\n");
> -		goto fail;
> +		goto free_bch;
>  	}
>  
>  	retval = nand_scan_tail(mtd);
>  	if (retval)
> -		goto fail;
> +		goto free_bch;
>  
>  	retval = read_factory_bbt(mtd);
>  	if (retval)
> -		goto fail;
> +		goto cleanup_nand;
>  
>  	retval = mtd_device_parse_register(mtd, part_probes, NULL, NULL, 0);
>  	if (retval)
> -		goto fail;
> +		goto cleanup_nand;
>  
>  	doc->mtd = mtd;
> +
>  	return 0;
>  
> -fail:
> -	nand_release(mtd); /* deletes partitions and mtd devices */
> +cleanup_nand:
> +	nand_cleanup(nand);
> +free_bch:
>  	free_bch(doc->bch);
> +free_nand:
>  	kfree(nand);
> -
> -fail_unmap:
> +unmap:
>  	iounmap(virtadr);
>  
>  	return retval;



-- 
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2018-03-27  7:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21 13:01 [PATCH v2 00/16] Fix probe functions error path Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 01/16] mtd: rawnand: brcmnand: fix probe function " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 02/16] mtd: rawnand: cafe: " Miquel Raynal
2018-03-27  8:02   ` Boris Brezillon
2018-03-21 13:01 ` [PATCH v2 03/16] mtd: rawnand: davinci: " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 04/16] mtd: rawnand: denali: " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 05/16] mtd: rawnand: docg4: fix the " Miquel Raynal
2018-03-27  7:59   ` Boris Brezillon [this message]
2018-03-21 13:01 ` [PATCH v2 06/16] mtd: rawnand: fsl_elbc: fix " Miquel Raynal
2018-03-27  7:56   ` Boris Brezillon
2018-03-21 13:01 ` [PATCH v2 07/16] mtd: rawnand: fsl_ifc: " Miquel Raynal
2018-03-27  7:57   ` Boris Brezillon
2018-03-21 13:01 ` [PATCH v2 08/16] mtd: rawnand: fsmc: fix and enhance " Miquel Raynal
2018-03-27  8:05   ` Boris Brezillon
2018-03-21 13:01 ` [PATCH v2 09/16] mtd: rawnand: mxc: fix " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 10/16] mtd: rawnand: omap2: fix the " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 11/16] mtd: rawnand: sh_flctl: " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 12/16] mtd: rawnand: tango: fix " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 13/16] mtd: rawnand: hisi504: fix and enhance the " Miquel Raynal
2018-03-27  8:56   ` Boris Brezillon
2018-03-21 13:01 ` [PATCH v2 14/16] mtd: rawnand: lpc32xx_mlc: " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 15/16] mtd: rawnand: lpc32xx_slc: " Miquel Raynal
2018-03-21 13:01 ` [PATCH v2 16/16] mtd: rawnand: s3c2410: " Miquel Raynal
2018-03-27  9:06   ` Boris Brezillon
2018-04-21 17:56     ` Miquel Raynal
2018-03-28  8:38 ` [PATCH v2 00/16] Fix probe functions " 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=20180327095928.5ff537af@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=kdasu.kdev@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=yamada.masahiro@socionext.com \
    /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