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@free-electrons.com>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
	linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: nftl/inftl: check mtd_erase() return value
Date: Mon, 12 Feb 2018 13:41:01 +0100	[thread overview]
Message-ID: <20180212134101.571f46d6@bbrezillon> (raw)
In-Reply-To: <20180124232434.32023-1-miquel.raynal@free-electrons.com>

On Thu, 25 Jan 2018 00:24:34 +0100
Miquel Raynal <miquel.raynal@free-electrons.com> wrote:

> Since the creation of mtd_erase(), the function can return a negative
> error code without updating the instr->state flag. This happens for
> instance when ->_erase() is not implemented or ->erasesize has an invalid
> value. The calling function should error out in this case.
> 
> Functions in nftlmount/inftlmount call mtd_erase() without checking the
> return code. The instr->state flag is checked but might not have been
> updated depending on the error path.
> 
> Add checks on the returned value of mtd_erase().
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
> ---
>  drivers/mtd/inftlmount.c | 7 +++++--
>  drivers/mtd/nftlmount.c  | 3 ++-
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
> index 8d6bb189ea8e..cab4a0b9f881 100644
> --- a/drivers/mtd/inftlmount.c
> +++ b/drivers/mtd/inftlmount.c
> @@ -219,7 +219,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
>  				 */
>  				instr->addr = ip->Reserved0 * inftl->EraseSize;
>  				instr->len = inftl->EraseSize;
> -				mtd_erase(mtd, instr);
> +				ret = mtd_erase(mtd, instr);
> +				if (ret < 0)
> +					return ret;
>  			}
>  			if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
>  				printk(KERN_WARNING "INFTL: Media Header "
> @@ -393,7 +395,8 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
>  	   mark only the failed block in the bbt. */
>  	for (physblock = 0; physblock < inftl->EraseSize;
>  	     physblock += instr->len, instr->addr += instr->len) {
> -		mtd_erase(inftl->mbd.mtd, instr);
> +		if (mtd_erase(inftl->mbd.mtd, instr < 0))

		    ^ mtd_erase(inftl->mbd.mtd, instr) < 0

which means you did not even compile test your patch :P.

> +			goto fail;
>  
>  		if (instr->state == MTD_ERASE_FAILED) {
>  			printk(KERN_WARNING "INFTL: error while formatting block %d\n",
> diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
> index 184c8fbfe465..8dbc40ab7d73 100644
> --- a/drivers/mtd/nftlmount.c
> +++ b/drivers/mtd/nftlmount.c
> @@ -331,7 +331,8 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
>  	instr->mtd = nftl->mbd.mtd;
>  	instr->addr = block * nftl->EraseSize;
>  	instr->len = nftl->EraseSize;
> -	mtd_erase(mtd, instr);
> +	if (mtd_erase(mtd, instr) < 0)
> +		goto fail;
>  
>  	if (instr->state == MTD_ERASE_FAILED) {
>  		printk("Error while formatting block %d\n", block);



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

  reply	other threads:[~2018-02-12 12:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 23:24 [PATCH] mtd: nftl/inftl: check mtd_erase() return value Miquel Raynal
2018-02-12 12:41 ` Boris Brezillon [this message]
2018-02-19 23:04   ` Miquel Raynal

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=20180212134101.571f46d6@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=miquel.raynal@free-electrons.com \
    --cc=richard@nod.at \
    /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