nvmem: layouts: u-boot-env: handle quotes in MAC post process
Subsystems (2)
PATCH 1/1 nvmem: layouts: u-boot-env: handle quotes in MAC post process
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 more variable and currently fails.
Add a second attempt when initial processing of the MAC address fails, by allowing a longer length and try parsing again if it seems to be quoted.
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.
--- drivers/nvmem/layouts/u-boot-env.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvmem/layouts/u-boot-env.c +6 -2
@@ -38,11 +38,15 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; +/* Handle quotation which increases length by 2 bytes if present. */ if (bytes !=MAC_ADDR_STR_LEN ) -return -EINVAL ; +if (bytes !=MAC_ADDR_STR_LEN +2 && !(*(char *)buf =='"' || *(char *)buf =='\'' )) +return -EINVAL ; +/* Handle quotation which offsets data by 1 byte if present. */ if (!mac_pton (buf, mac)) -return -EINVAL ; +if (!mac_pton (buf +1 , mac)) +return -EINVAL ;if (index)eth_addr_add (mac, index);
Signature · 1 line
2.30.2
Srinivas Kandagatla
maintainerQuoted 11 lines · Michael C. Pratt
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 more variable and currently fails.
Add a second attempt when initial processing of the MAC address fails, by allowing a longer length and try parsing again if it seems to be quoted.
Quoted 8 lines
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 <[email protected]>--- drivers/nvmem/layouts/u-boot-env.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
this patch looks stale as
commit 45cb0223740b863089ce3cc523155cf7a55e1479
Author: Tomasz Maciej Nowak <[email protected]> Date: Sat May 30 21:53:33 2026 +0100
nvmem: layouts: u-boot-env: check earlier for ethaddr length
already has some changes in this area,
--srini
Quoted 23 lines
drivers/nvmem/layouts/u-boot-env.c +6
-2@@ -38,11 +38,15 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i {u8 mac[ETH_ALEN ]; +/* Handle quotation which increases length by 2 bytes if present. */ if (bytes !=MAC_ADDR_STR_LEN ) -return -EINVAL ; +if (bytes !=MAC_ADDR_STR_LEN +2 && !(*(char *)buf =='"' || *(char *)buf =='\'' )) +return -EINVAL ; +/* Handle quotation which offsets data by 1 byte if present. */ if (!mac_pton (buf, mac)) -return -EINVAL ; +if (!mac_pton (buf +1 , mac)) +return -EINVAL ;if (index)eth_addr_add (mac, index);