[PATCH 09/10] nvmem: meson-efuse: Detect short reads and writes from Secure Monitor

Lee Jones lee at kernel.org
Thu Dec 3 00:26:10 PST 2026


meson_efuse_read() and meson_efuse_write() treat any non-negative byte
count returned by meson_sm_call_read() or meson_sm_call_write() as
success and return 0, silently hiding partial reads or writes.

Return -EIO when meson_sm_call_write() reports a byte count other than
bytes, or when meson_sm_call_read() returns a non-zero byte count that
does not match bytes (preserving the 0 return convention documented by
meson_sm_call_read()).

Fixes: 7a0a6d0a7c80 ("nvmem: meson-efuse: Fix return value of nvmem callbacks")
Closes: https://sashiko.dev/#/bug/linux-990a1e10-e629-4b29-956e-2b2d39ac8f4a
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---

Cc: Carlo Caione <carlo at endlessm.com>
Cc: Dan Carpenter <error27 at gmail.com>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc: Jerome Brunet <jbrunet at baylibre.com>
Cc: Joy Chakraborty <joychakr at google.com>
Cc: Kevin Hilman <khilman at baylibre.com>
Cc: linux-amlogic at lists.infradead.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: Martin Blumenstingl <martin.blumenstingl at googlemail.com>
Cc: Neil Armstrong <neil.armstrong at linaro.org>
Cc: Srinivas Kandagatla <srini at kernel.org>

 drivers/nvmem/meson-efuse.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index e8f384098be5..383ee9281693 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -22,8 +22,12 @@ static int meson_efuse_read(void *context, unsigned int offset,
 
 	ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
 				 bytes, 0, 0, 0);
+	if (ret < 0)
+		return ret;
+	if (ret && ret != bytes)
+		return -EIO;
 
-	return ret < 0 ? ret : 0;
+	return 0;
 }
 
 static int meson_efuse_write(void *context, unsigned int offset,
@@ -34,8 +38,12 @@ static int meson_efuse_write(void *context, unsigned int offset,
 
 	ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
 				  bytes, 0, 0, 0);
+	if (ret < 0)
+		return ret;
+	if (ret != bytes)
+		return -EIO;
 
-	return ret < 0 ? ret : 0;
+	return 0;
 }
 
 static const struct of_device_id meson_efuse_match[] = {
-- 
2.56.1.911.g883d8bcb20-goog




More information about the linux-arm-kernel mailing list