| From 2aa4ad626ee7f817a8f4715a47b318cfdc1714c9 Mon Sep 17 00:00:00 2001 |
| From: =?UTF-8?q?Steffen=20B=C3=A4tz?= <steffen@innosonix.de> |
| Date: Sat, 12 Jul 2025 19:17:27 +0100 |
| Subject: nvmem: imx-ocotp: fix MAC address byte length |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| From: Steffen Bätz <steffen@innosonix.de> |
| |
| commit 2aa4ad626ee7f817a8f4715a47b318cfdc1714c9 upstream. |
| |
| The commit "13bcd440f2ff nvmem: core: verify cell's raw_len" caused an |
| extension of the "mac-address" cell from 6 to 8 bytes due to word_size |
| of 4 bytes. This led to a required byte swap of the full buffer length, |
| which caused truncation of the mac-address when read. |
| |
| Previously, the mac-address was incorrectly truncated from |
| 70:B3:D5:14:E9:0E to 00:00:70:B3:D5:14. |
| |
| Fix the issue by swapping only the first 6 bytes to correctly pass the |
| mac-address to the upper layers. |
| |
| Fixes: 13bcd440f2ff ("nvmem: core: verify cell's raw_len") |
| Cc: stable@vger.kernel.org |
| Signed-off-by: Steffen Bätz <steffen@innosonix.de> |
| Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> |
| Signed-off-by: Srinivas Kandagatla <srini@kernel.org> |
| Link: https://lore.kernel.org/r/20250712181729.6495-3-srini@kernel.org |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| --- |
| drivers/nvmem/imx-ocotp-ele.c | 5 ++++- |
| drivers/nvmem/imx-ocotp.c | 5 ++++- |
| 2 files changed, 8 insertions(+), 2 deletions(-) |
| |
| --- a/drivers/nvmem/imx-ocotp-ele.c |
| +++ b/drivers/nvmem/imx-ocotp-ele.c |
| @@ -12,6 +12,7 @@ |
| #include <linux/of.h> |
| #include <linux/platform_device.h> |
| #include <linux/slab.h> |
| +#include <linux/if_ether.h> /* ETH_ALEN */ |
| |
| enum fuse_type { |
| FUSE_FSB = BIT(0), |
| @@ -118,9 +119,11 @@ static int imx_ocotp_cell_pp(void *conte |
| int i; |
| |
| /* Deal with some post processing of nvmem cell data */ |
| - if (id && !strcmp(id, "mac-address")) |
| + if (id && !strcmp(id, "mac-address")) { |
| + bytes = min(bytes, ETH_ALEN); |
| for (i = 0; i < bytes / 2; i++) |
| swap(buf[i], buf[bytes - i - 1]); |
| + } |
| |
| return 0; |
| } |
| --- a/drivers/nvmem/imx-ocotp.c |
| +++ b/drivers/nvmem/imx-ocotp.c |
| @@ -23,6 +23,7 @@ |
| #include <linux/platform_device.h> |
| #include <linux/slab.h> |
| #include <linux/delay.h> |
| +#include <linux/if_ether.h> /* ETH_ALEN */ |
| |
| #define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the |
| * OTP Bank0 Word0 |
| @@ -227,9 +228,11 @@ static int imx_ocotp_cell_pp(void *conte |
| int i; |
| |
| /* Deal with some post processing of nvmem cell data */ |
| - if (id && !strcmp(id, "mac-address")) |
| + if (id && !strcmp(id, "mac-address")) { |
| + bytes = min(bytes, ETH_ALEN); |
| for (i = 0; i < bytes / 2; i++) |
| swap(buf[i], buf[bytes - i - 1]); |
| + } |
| |
| return 0; |
| } |