From: Johannes Zink <j.zink@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
Barebox List <barebox@lists.infradead.org>
Cc: Johannes Zink <jzi@pengutronix.de>
Subject: Re: [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes
Date: Thu, 08 Dec 2022 15:12:04 +0100 [thread overview]
Message-ID: <53712712eb694f6be6a09746eb569a78f38b8ae5.camel@pengutronix.de> (raw)
In-Reply-To: <20221123114245.3258194-1-s.hauer@pengutronix.de>
On Wed, 2022-11-23 at 12:42 +0100, Sascha Hauer wrote:
> Return successfully when mtd_peb_read() or mtd_peb_write() is passed
> a
> zero length so that the callers do not have to handle this case.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Johannes Zink <j.zink@pengutronix.de> (i.MX7 with ubi on
NAND Flash)
> ---
> drivers/mtd/peb.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
> index 8443ed86bc..a17d42885e 100644
> --- a/drivers/mtd/peb.c
> +++ b/drivers/mtd/peb.c
> @@ -205,10 +205,12 @@ int mtd_peb_read(struct mtd_info *mtd, void
> *buf, int pnum, int offset,
> return -EINVAL;
> if (offset < 0 || offset + len > mtd->erasesize)
> return -EINVAL;
> - if (len <= 0)
> + if (len < 0)
> return -EINVAL;
> if (mtd_peb_is_bad(mtd, pnum))
> return -EINVAL;
> + if (!len)
> + return 0;
>
> /* Deliberately corrupt the buffer */
> *((uint8_t *)buf) ^= 0xFF;
> @@ -388,12 +390,14 @@ int mtd_peb_write(struct mtd_info *mtd, const
> void *buf, int pnum, int offset,
> return -EINVAL;
> if (offset < 0 || offset + len > mtd->erasesize)
> return -EINVAL;
> - if (len <= 0)
> + if (len < 0)
> return -EINVAL;
> if (len % (mtd->writesize >> mtd->subpage_sft))
> return -EINVAL;
> if (mtd_peb_is_bad(mtd, pnum))
> return -EINVAL;
> + if (!len)
> + return 0;
>
> if (mtd_peb_emulate_write_failure()) {
> dev_err(&mtd->dev, "Cannot write %d bytes to PEB
> %d:%d (emulated)\n",
--
Pengutronix e.K. | Johannes Zink |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2022-12-08 14:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 11:42 Sascha Hauer
2022-11-23 11:42 ` [PATCH 2/2] fastboot: ubiformat: Fix writing sparse images Sascha Hauer
2022-12-08 14:12 ` Johannes Zink [this message]
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=53712712eb694f6be6a09746eb569a78f38b8ae5.camel@pengutronix.de \
--to=j.zink@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jzi@pengutronix.de \
--cc=s.hauer@pengutronix.de \
/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