From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Johannes Zink <jzi@pengutronix.de>
Subject: [PATCH 1/2] mtd: peb: return success for reading/writing 0 bytes
Date: Wed, 23 Nov 2022 12:42:44 +0100 [thread overview]
Message-ID: <20221123114245.3258194-1-s.hauer@pengutronix.de> (raw)
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
next reply other threads:[~2022-11-23 11:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 11:42 Sascha Hauer [this message]
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
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=20221123114245.3258194-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jzi@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