[PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes

Sascha Hauer s.hauer at pengutronix.de
Wed Nov 23 03:42:44 PST 2022


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>
---
 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",
-- 
2.30.2




More information about the barebox mailing list