Skip to content

Commit 2aa4ad6

Browse files
Steffen Bätzgregkh
authored andcommitted
nvmem: imx-ocotp: fix MAC address byte length
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: 13bcd44 ("nvmem: core: verify cell's raw_len") Cc: [email protected] Signed-off-by: Steffen Bätz <[email protected]> Tested-by: Alexander Stein <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ae68ad3 commit 2aa4ad6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

drivers/nvmem/imx-ocotp-ele.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/of.h>
1313
#include <linux/platform_device.h>
1414
#include <linux/slab.h>
15+
#include <linux/if_ether.h> /* ETH_ALEN */
1516

1617
enum fuse_type {
1718
FUSE_FSB = BIT(0),
@@ -118,9 +119,11 @@ static int imx_ocotp_cell_pp(void *context, const char *id, int index,
118119
int i;
119120

120121
/* Deal with some post processing of nvmem cell data */
121-
if (id && !strcmp(id, "mac-address"))
122+
if (id && !strcmp(id, "mac-address")) {
123+
bytes = min(bytes, ETH_ALEN);
122124
for (i = 0; i < bytes / 2; i++)
123125
swap(buf[i], buf[bytes - i - 1]);
126+
}
124127

125128
return 0;
126129
}

drivers/nvmem/imx-ocotp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/platform_device.h>
2424
#include <linux/slab.h>
2525
#include <linux/delay.h>
26+
#include <linux/if_ether.h> /* ETH_ALEN */
2627

2728
#define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the
2829
* OTP Bank0 Word0
@@ -227,9 +228,11 @@ static int imx_ocotp_cell_pp(void *context, const char *id, int index,
227228
int i;
228229

229230
/* Deal with some post processing of nvmem cell data */
230-
if (id && !strcmp(id, "mac-address"))
231+
if (id && !strcmp(id, "mac-address")) {
232+
bytes = min(bytes, ETH_ALEN);
231233
for (i = 0; i < bytes / 2; i++)
232234
swap(buf[i], buf[bytes - i - 1]);
235+
}
233236

234237
return 0;
235238
}

0 commit comments

Comments
 (0)