[PATCH] nvmem: layouts: u-boot-env: check earlier for ethaddr length

Tomasz Maciej Nowak posted 1 patch 2 weeks, 3 days ago
drivers/nvmem/layouts/u-boot-env.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
[PATCH] nvmem: layouts: u-boot-env: check earlier for ethaddr length
Posted by Tomasz Maciej Nowak 2 weeks, 3 days ago
From: Tomasz Maciej Nowak <tmn505@gmail.com>

Unfortunately the ethaddr value in U-Boot environment might be enclosed
in single/double quotes or be something completely different, which can
make it longer than ETH_ALEN, then nvmem will return EINVAL. Move the
check for length earlier, so even if ethaddr is something different,
nvmem could still present it.

Signed-off-by: Tomasz Maciej Nowak <tmn505@gmail.com>
---
 drivers/nvmem/layouts/u-boot-env.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index f27f387bb52a..dd3f541728bf 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -38,9 +38,6 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i
 {
 	u8 mac[ETH_ALEN];
 
-	if (bytes != MAC_ADDR_STR_LEN)
-		return -EINVAL;
-
 	if (!mac_pton(buf, mac))
 		return -EINVAL;
 
@@ -75,7 +72,7 @@ static int u_boot_env_parse_cells(struct device *dev, struct nvmem_device *nvmem
 		info.offset = data_offset + value - data;
 		info.bytes = strlen(value);
 		info.np = of_get_child_by_name(dev->of_node, info.name);
-		if (!strcmp(var, "ethaddr")) {
+		if ((!strcmp(var, "ethaddr")) && (info.bytes == MAC_ADDR_STR_LEN)) {
 			info.raw_len = strlen(value);
 			info.bytes = ETH_ALEN;
 			info.read_post_process = u_boot_env_read_post_process_ethaddr;
-- 
2.53.0