2019-07-27 20:15:57

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH v2] nvmem: meson-mx-efuse: allow reading data smaller than word_size

Some Amlogic boards store the Ethernet MAC address inside the eFuse. The
Ethernet MAC address uses 6 bytes. The existing logic in
meson_mx_efuse_read() would write beyond the end of the data buffer when
trying to read data with a size that is not aligned to word_size (4
bytes on Meson8, Meson8b and Meson8m2).

Calculate the remaining data to copy inside meson_mx_efuse_read() so
reading 6 bytes doesn't write beyond the end of the data buffer.

Signed-off-by: Martin Blumenstingl <[email protected]>
---
Changes since v1:
- switch from min() to min_t() to get rid of a compiler warning


drivers/nvmem/meson-mx-efuse.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c
index 2976aef87c82..e8fc0baa09e7 100644
--- a/drivers/nvmem/meson-mx-efuse.c
+++ b/drivers/nvmem/meson-mx-efuse.c
@@ -155,7 +155,8 @@ static int meson_mx_efuse_read(void *context, unsigned int offset,
if (err)
break;

- memcpy(buf + i, &tmp, efuse->config.word_size);
+ memcpy(buf + i, &tmp,
+ min_t(size_t, bytes - i, efuse->config.word_size));
}

meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1,
--
2.22.0



2019-07-29 13:58:52

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH v2] nvmem: meson-mx-efuse: allow reading data smaller than word_size

On 27/07/2019 21:34, Martin Blumenstingl wrote:
> Some Amlogic boards store the Ethernet MAC address inside the eFuse. The
> Ethernet MAC address uses 6 bytes. The existing logic in
> meson_mx_efuse_read() would write beyond the end of the data buffer when
> trying to read data with a size that is not aligned to word_size (4
> bytes on Meson8, Meson8b and Meson8m2).
>
> Calculate the remaining data to copy inside meson_mx_efuse_read() so
> reading 6 bytes doesn't write beyond the end of the data buffer.
>
> Signed-off-by: Martin Blumenstingl <[email protected]>
> ---
> Changes since v1:
> - switch from min() to min_t() to get rid of a compiler warning
>
>
> drivers/nvmem/meson-mx-efuse.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c
> index 2976aef87c82..e8fc0baa09e7 100644
> --- a/drivers/nvmem/meson-mx-efuse.c
> +++ b/drivers/nvmem/meson-mx-efuse.c
> @@ -155,7 +155,8 @@ static int meson_mx_efuse_read(void *context, unsigned int offset,
> if (err)
> break;
>
> - memcpy(buf + i, &tmp, efuse->config.word_size);
> + memcpy(buf + i, &tmp,
> + min_t(size_t, bytes - i, efuse->config.word_size));
> }
>
> meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1,
>

Reviewed-by: Neil Armstrong <[email protected]>

2019-08-06 10:05:56

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH v2] nvmem: meson-mx-efuse: allow reading data smaller than word_size



On 27/07/2019 20:34, Martin Blumenstingl wrote:
> Some Amlogic boards store the Ethernet MAC address inside the eFuse. The
> Ethernet MAC address uses 6 bytes. The existing logic in
> meson_mx_efuse_read() would write beyond the end of the data buffer when
> trying to read data with a size that is not aligned to word_size (4
> bytes on Meson8, Meson8b and Meson8m2).
>
> Calculate the remaining data to copy inside meson_mx_efuse_read() so
> reading 6 bytes doesn't write beyond the end of the data buffer.
>
> Signed-off-by: Martin Blumenstingl <[email protected]>
> ---

Applied Thanks,
Srini