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
  0 siblings, 1 reply; 2+ 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] 2+ messages in thread

* [PATCH 2/2] fastboot: ubiformat: Fix writing sparse images
  2022-11-23 11:42 [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes Sascha Hauer
@ 2022-11-23 11:42 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-11-23 11:42 UTC (permalink / raw)
  To: Barebox List; +Cc: Johannes Zink

in ubiformat_write() we may not write trailing empty areas in erase
blocks as UBI assumes them to be empty and writable.

This code path is used when fastboot handles sparse images.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/ubiformat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/ubiformat.c b/common/ubiformat.c
index 1edfc5b2a3..d8399ad9d6 100644
--- a/common/ubiformat.c
+++ b/common/ubiformat.c
@@ -745,6 +745,7 @@ int ubiformat_write(struct mtd_info *mtd, const void *buf, size_t count,
 
 	while (count) {
 		size_t now = mtd->erasesize - offset_in_peb;
+		int new_len;
 
 		if (now > count)
 			now = count;
@@ -780,7 +781,8 @@ int ubiformat_write(struct mtd_info *mtd, const void *buf, size_t count,
 			}
 		}
 
-		ret = mtd_peb_write(mtd, buf, peb, offset_in_peb, now);
+		new_len = drop_ffs(mtd, buf, now);
+		ret = mtd_peb_write(mtd, buf, peb, offset_in_peb, new_len);
 		if (ret < 0)
 			return ret;
 
-- 
2.30.2




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

end of thread, other threads:[~2022-11-23 11:45 UTC | newest]

Thread overview: 2+ 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

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