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

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Dec 3 00:54:36 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmem: meson_efuse_read() exempts 0 return from short-read
  detection
--

commit f954b4c965de299d7ba849b64117c5f529cb5207
Author: Lee Jones <lee at kernel.org>

nvmem: meson-efuse: Detect short reads and writes from Secure Monitor

This commit checks the byte count returned by meson_sm_call_read() and
meson_sm_call_write() in meson_efuse_read() and meson_efuse_write(),
returning -EIO on short transfers instead of silently returning 0.

> diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
> index 029cad70a0af1..0482057219d22 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;
>  }

[Severity: Medium]
Should this check "if (ret != bytes)" directly instead of exempting ret == 0?

SM_EFUSE_READ returns the byte count on success; the 0-return fallback in
meson_sm_call_read() was added by 7a9bc330df9b ("firmware: meson-sm: Allow 0
as valid return value") for special commands like SM_GET_CHIP_ID that do not
report a length.

If Secure Monitor returns 0 for a non-zero SM_EFUSE_READ, meson_sm_call_read()
copies stale data from fw->sm_shmem_out_base into val and returns 0.  With the
"ret &&" guard, meson_efuse_read() treats that 0-byte read as success and
returns stale shared memory to nvmem callers instead of -EIO.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796286324.git.lee@kernel.org?part=9



More information about the linux-amlogic mailing list