From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Miquel Raynal <miquel.raynal@free-electrons.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Marek Vasut <marek.vasut@gmail.com>,
Richard Weinberger <richard@nod.at>,
Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
linux-mtd@lists.infradead.org, Peter Pan <peterpansjtu@gmail.com>,
Frieder Schrempf <frieder.schrempf@exceet.de>
Subject: Re: [PATCH] mtd: Make sure the device supports erase operations in mtd_erase()
Date: Tue, 23 Jan 2018 11:24:24 +0100 [thread overview]
Message-ID: <20180123112424.36e5e426@bbrezillon> (raw)
In-Reply-To: <20180123090046.503b1129@xps13>
On Tue, 23 Jan 2018 09:00:46 +0100
Miquel Raynal <miquel.raynal@free-electrons.com> wrote:
> Hello Boris,
>
> On Mon, 22 Jan 2018 10:38:01 +0100
> Boris Brezillon <boris.brezillon@free-electrons.com> wrote:
>
> > Some devices do not implement ->_erase() or have an invalid ->erasesize
> > value. In this case, mtd_erase() should return -ENOTSUPP.
> >
> > Note that the test is not done on the MTD_NO_ERASE flag because this
> > flag means 'erasing a block before writing to it is unnecessary',
> > not 'the erase operation is not supported'. Actually, some drivers are
> > setting the MTD_NO_ERASE flag but still implementing the ->_erase()
> > hook and setting a valid ->erasesize value.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> > drivers/mtd/mtdcore.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> > index d7ab091b36b2..f24144cbc99c 100644
> > --- a/drivers/mtd/mtdcore.c
> > +++ b/drivers/mtd/mtdcore.c
> > @@ -971,10 +971,14 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);
> > */
> > int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
> > {
> > + if (!mtd->erasesize || !mtd->_erase)
> > + return -ENOTSUPP;
> > +
> > if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr)
> > return -EINVAL;
> > if (!(mtd->flags & MTD_WRITEABLE))
> > return -EROFS;
>
> This remark is not inherent to this patch in particular but as we are
> adding a new error path, I thought it might be interesting to also
> patch:
> - INFTL_formatblock() from inftlmount.c [1] (mtd_erase called twice)
> - NFTL_formatblock() from nftlmount.c [2]
>
> They both call mtd_erase() without checking the return code and then
> error out only if instr->state == MTD_ERASE_FAILED, which has not been
> set before quitting mtd_erase() in the conditions above. I guess the
> right thing to do is to add another condition in both functions on the
> return code of mtd_erase(). What do you think?
This sounds reasonable.
>
> Otherwise:
> Reviewed-by: Miquel Raynal <miquel.raynal@free-electrons.com>
Thanks.
Boris
>
> Have a good day,
> Miquèl
>
> [1]
> http://elixir.free-electrons.com/linux/latest/source/drivers/mtd/inftlmount.c#L396
> [2]
> http://elixir.free-electrons.com/linux/latest/source/drivers/mtd/nftlmount.c#L334
next prev parent reply other threads:[~2018-01-23 10:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 9:38 [PATCH] mtd: Make sure the device supports erase operations in mtd_erase() Boris Brezillon
2018-01-23 8:00 ` Miquel Raynal
2018-01-23 10:24 ` Boris Brezillon [this message]
2018-02-17 8:38 ` 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=20180123112424.36e5e426@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=frieder.schrempf@exceet.de \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=miquel.raynal@free-electrons.com \
--cc=peterpansjtu@gmail.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