From: "Marek Behún" <kabel@kernel.org>
To: Jagan Teki <jagan@amarulasolutions.com>, Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.denx.de,
"Patrick Delaunay" <patrick.delaunay@st.com>,
"Pali Rohár" <pali@kernel.org>,
"Patrice Chotard" <patrice.chotard@foss.st.com>,
"Marek Vasut" <marex@denx.de>, "Pratyush Yadav" <p.yadav@ti.com>,
"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-spi v3 05/10] mtd: spi-flash: Check for zero length in legacy spi_flash_*()
Date: Tue, 5 Oct 2021 15:56:01 +0200 [thread overview]
Message-ID: <20211005135606.2246-6-kabel@kernel.org> (raw)
In-Reply-To: <20211005135606.2246-1-kabel@kernel.org>
From: Marek Behún <marek.behun@nic.cz>
Check for zero length in the legacy spi_flash_read() /
spi_flash_write() / spi_flash_erase() functions.
On zero length, return 0 immediately, don't call the underlying method.
Rationale:
- these legacy functions call the _read(), _write() and _erase() methods
of struct mtd
- the DM callers of these methods already check for zero length
- making all callers of these methods check for zero length makes it
possible to remove the check from implementations of these _read(),
_write() and _erase() methods
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
include/spi_flash.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 3d747c925b..4d4ae89c19 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -165,6 +165,9 @@ static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
struct mtd_info *mtd = &flash->mtd;
size_t retlen;
+ if (!len)
+ return 0;
+
return mtd->_read(mtd, offset, len, &retlen, buf);
}
@@ -174,6 +177,9 @@ static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
struct mtd_info *mtd = &flash->mtd;
size_t retlen;
+ if (!len)
+ return 0;
+
return mtd->_write(mtd, offset, len, &retlen, buf);
}
@@ -188,6 +194,9 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
return -EINVAL;
}
+ if (!len)
+ return 0;
+
memset(&instr, 0, sizeof(instr));
instr.addr = offset;
instr.len = len;
--
2.32.0
next prev parent reply other threads:[~2021-10-05 13:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 13:55 [PATCH u-boot-spi v3 00/10] Fix `mtd erase` when used with mtdpart Marek Behún
2021-10-05 13:55 ` [PATCH u-boot-spi v3 01/10] mtd: spi-nor-core: Try cleaning up in case writing BAR failed Marek Behún
2021-10-05 13:55 ` [PATCH u-boot-spi v3 02/10] mtd: spi-nor-core: Check return value of write_enable() in spi_nor_erase() Marek Behún
2021-10-05 13:55 ` [PATCH u-boot-spi v3 03/10] mtd: spi-nor-core: Don't overwrite return value if it is non-zero Marek Behún
2021-10-05 13:56 ` [PATCH u-boot-spi v3 04/10] mtd: spi-nor-core: Check return value of write_disable() in spi_nor_erase() Marek Behún
2021-10-05 13:56 ` Marek Behún [this message]
2021-10-05 13:56 ` [PATCH u-boot-spi v3 06/10] mtd: spi-nor-core: Don't check for zero length in spi_nor_write() / spi_nor_erase() Marek Behún
2021-10-05 13:56 ` [PATCH u-boot-spi v3 07/10] mtd: spi-nor-core: Call mtd_erase_callback() from spi_nor_erase() Marek Behún
2021-10-05 13:56 ` [PATCH u-boot-spi v3 08/10] mtd: spi-nor-core: Check for ctrlc() in spi_nor_erase() Marek Behún
2021-10-05 13:56 ` [PATCH u-boot-spi v3 09/10] mtd: mtdpart: Make mtdpart's _erase method sane Marek Behún
2021-10-05 13:56 ` [PATCH u-boot-spi v3 10/10] mtd: Remove mtd_erase_callback() entirely Marek Behún
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=20211005135606.2246-6-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=jagan@amarulasolutions.com \
--cc=marek.behun@nic.cz \
--cc=marex@denx.de \
--cc=p.yadav@ti.com \
--cc=pali@kernel.org \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@st.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.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