Skip to contentSkip to conversation

nvmem: layouts: u-boot-env: handle quotes in MAC post process

PATCH RESEND New Michael C. Pratt 1 participant 1 message Oct 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 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 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.

---
v1: https://lore.kernel.org/all/[email protected]/
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(+)
drivers/nvmem/layouts/u-boot-env.c +7 -0
index 33ec2350386f..588996c1c11b 100644
@@ -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);
 	}
Signature · 1 line
2.30.2