* [PATCH v2] nvmem: layouts: u-boot-env: handle quotes in MAC post process
@ 2026-10-08 3:41 Michael C. Pratt
0 siblings, 0 replies; only message in thread
From: Michael C. Pratt @ 2026-10-08 3:41 UTC (permalink / raw)
To: linux-kernel
Cc: Michael C. Pratt, Rafał Miłecki, Christian Marangi,
Tomasz Maciej Nowak, Srinivas Kandagatla
Although it is not common, some board models from some vendors have
a MAC address stored in u-boot environment as a quoted form, e.g.
ethaddr="AA:BB:CC:DD:EE:FF"
This is acceptable formatting for a u-boot environment variable, however,
it makes parsing MACs in post processing inconsistent and currently fails.
Add a second condition for processing to match the MAC address with quotes
by allowing a longer length and setting a shifted offset to compensate.
The mac_pton() function has strict behavior on the length and location
of delimiters for each octet and that each digit is hexadecimal,
so attempting different offsets of the same string is not problematic.
Signed-off-by: Michael C. Pratt <mcpratt@pm.me>
---
v1: https://lore.kernel.org/all/20260820211654.8794-1-mcpratt@pm.me/
v2: rebased and relocated changes to match style due to commit
45cb0223740b ("nvmem: layouts: u-boot-env: check earlier for ethaddr length")
drivers/nvmem/layouts/u-boot-env.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index 33ec2350386f..588996c1c11b 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -77,6 +77,13 @@ static int u_boot_env_parse_cells(struct device *dev, struct nvmem_device *nvmem
info.bytes = ETH_ALEN;
info.read_post_process = u_boot_env_read_post_process_ethaddr;
}
+ /* Handle quotation which increases length by 2 and offset by 1 if present. */
+ if (!strcmp(var, "ethaddr") && info.bytes == MAC_ADDR_STR_LEN + 2) {
+ info.offset = data_offset + value - data + 1;
+ info.raw_len = strlen(value);
+ info.bytes = ETH_ALEN;
+ info.read_post_process = u_boot_env_read_post_process_ethaddr;
+ }
nvmem_add_one_cell(nvmem, &info);
}
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-08 3:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 3:41 [PATCH v2] nvmem: layouts: u-boot-env: handle quotes in MAC post process Michael C. Pratt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®