[PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes
Johannes Zink
j.zink at pengutronix.de
Thu Dec 8 06:12:04 PST 2022
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 at pengutronix.de>
Tested-by: Johannes Zink <j.zink at 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 |
More information about the barebox
mailing list