mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes
@ 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 ` [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes Johannes Zink
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-11-23 11:42 UTC (permalink / raw)
  To: Barebox List; +Cc: Johannes Zink

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>
---
 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-08 14:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 11:42 [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes Sascha Hauer
2022-11-23 11:42 ` [PATCH 2/2] fastboot: ubiformat: Fix writing sparse images Sascha Hauer
2022-12-08 14:12 ` [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes Johannes Zink

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox