mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michael C. Pratt" <mcpratt@pm.me>
To: linux-kernel@vger.kernel.org
Cc: "Michael C. Pratt" <mcpratt@pm.me>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Christian Marangi" <ansuelsmth@gmail.com>,
	"Tomasz Maciej Nowak" <tmn505@gmail.com>,
	"Srinivas Kandagatla" <srini@kernel.org>
Subject: [PATCH v2] nvmem: layouts: u-boot-env: handle quotes in MAC post process
Date: Thu, 08 Oct 2026 03:41:49 +0000	[thread overview]
Message-ID: <20261008034108.15143-1-mcpratt@pm.me> (raw)

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



                 reply	other threads:[~2026-10-08  3:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261008034108.15143-1-mcpratt@pm.me \
    --to=mcpratt@pm.me \
    --cc=ansuelsmth@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafal@milecki.pl \
    --cc=srini@kernel.org \
    --cc=tmn505@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®