From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.149 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093064; b=AqwqpPajUKrSpms1QEJOeDrUNmmPsod8fWWvXt9PurNVWSccn+Z6EmldWChaoLstJS1Q vrWlSYBKLATSld0a0UJcqz15ffXq569uzxpPlth1VC037z3lBTlo+PBrYrIqHzQnPT5oi 2GxBhv92g+Yb14C6CcDQk00zSF79lEOQD9M1gxoACH2leDALtkAvKFL0Os34lpYO18KJc 50mW53fmpc3S0W+Qxe5akiHMFYYsLMRA6ja8lWk7gVUl3YbCnemlOh42qX6rafaOUmQZf scKxIiQ2gACNwQl8zNv82j3fGRksLEGkNPmoSeetDK/BQTeYDfmZrDvLuGMBBAWTw9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093064; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=IwDBP7pBJdxkei3n+lO0ovEPI/Omz7fdnqJm8VJ5POg=; b=PKARGWjmSYs7mzU85pgkf+xibVdVeS0D7GBUk4eO//mCqXihrySkxpbJgymFHZtibwWG G6IdJAVKGTGkjzW7QKGZNfbPCdOvxaSLfBj0BGn2a/pmd1Ahx9vJdg45nyKQvIVqVPHUm z4Tg98aaWr0/7pgHaIolDpye+tuCPfuCzZYBMVdoERv9ryprG3f1wvyiN9jqwEwOZdMkr b6CwxLCyad2+Vi9CuSuluadzhfvFciiPAyN8HYwgXKYEQVvql2kfn7VhE7HpPzb4sGoJP NkrLqc4G7Is/UimGOyKULQEJ55bbZsa5mdHUYLEGGhCjyEPxwo8Tl5wkrcpGmn5vfJQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=xiaopeng.com; spf=pass smtp.mailfrom=xiaopeng.com; dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=f14SfP8d; arc=none smtp.remote-ip=115.124.28.149 Received: from out28-149.mail.aliyun.com (out28-149.mail.aliyun.com [115.124.28.149]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 190E2606A31A; Tue, 1 Dec 2026 02:44:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 190E2606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=f14SfP8d DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1796093059; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=IwDBP7pBJdxkei3n+lO0ovEPI/Omz7fdnqJm8VJ5POg=; b=f14SfP8d+7Yz5qqr47agOdZL2lZVEMA0kVLc8G95Z9onZkt+hONMLkLNoPJlkcvO4+7reEu6Z+cqNd/dei7YX/8YTB9TmWWf/y2a704TZk62eC0IfUBaCHZM7qshJ2lC10NuTgNM0mR/75xCBBcNKUYZdlttHdSFB8gPrpDGFb8= X-Alimail-AntiSpam:AC=CONTINUE;BC=0.07436259|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00415204-3.12034e-05-0.995817;FP=18020985227750442168|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037034020;MF=liuc63@xiaopeng.com;NM=1;PH=DS;RN=15;RT=15;SR=0;TI=SMTPD_---.kDtpeZQ_1796093057; Received: from localhost(mailfrom:liuc63@xiaopeng.com fp:SMTPD_---.kDtpeZQ_1796093057 cluster:ay29) by smtp.aliyun-inc.com; Tue, 01 Dec 2026 10:44:18 +0800 From: Liu Chao To: "Greg Kroah-Hartman" , "Andrew Morton" Cc: "Andy Shevchenko" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , khtsai@google.com, fangxy@xiaopeng.com, "Randy Dunlap" , dbrownell@users.sourceforge.net, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v7 1/2] lib/net_utils: allow mac_pton() to take a custom delimiter Date: Tue, 1 Dec 2026 10:44:14 +0800 Message-ID: <20261201024415.3340593-2-liuc63@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201024415.3340593-1-liuc63@xiaopeng.com> References: <20261201024415.3340593-1-liuc63@xiaopeng.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit mac_pton() hardcodes ':' as the only accepted separator, which pushes callers that need a different notation to open-code their own parser. Split the body out into parse_mac_pton() taking the set of accepted delimiters as a string, and turn mac_pton() into a static inline wrapper passing ":" so that every existing caller keeps its current behaviour. The strnlen() guard still runs before any delimiter is inspected, so strchr() is never handed a NUL character. No functional change intended. Suggested-by: Andy Shevchenko Signed-off-by: Liu Chao Reviewed-by: Andy Shevchenko --- v7: no change. v6: no change. v5: reword the parse_mac_pton() kernel-doc to say @s must be at least MAC_ADDR_STR_LEN characters long and that only the first MAC_ADDR_STR_LEN characters are checked, the rest ignored. No code change. v4: no change. v3: pick up Andy's Reviewed-by, no code change. v2: new patch, split out of the u_ether fix at Andy's suggestion. Link: https://lore.kernel.org/all/20261117090110.3263592-2-liuc63@xiaopeng.com/ include/linux/hex.h | 7 ++++++- lib/net_utils.c | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/linux/hex.h b/include/linux/hex.h index 2618382e5b0c..408825478cda 100644 --- a/include/linux/hex.h +++ b/include/linux/hex.h @@ -30,6 +30,11 @@ extern int hex_to_bin(unsigned char ch); extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); extern char *bin2hex(char *dst, const void *src, size_t count); -bool mac_pton(const char *s, u8 *mac); +bool parse_mac_pton(const char *s, u8 *mac, const char *delim); + +static inline bool mac_pton(const char *s, u8 *mac) +{ + return parse_mac_pton(s, mac, ":"); +} #endif diff --git a/lib/net_utils.c b/lib/net_utils.c index 215cda672fee..fd76b9ab3f24 100644 --- a/lib/net_utils.c +++ b/lib/net_utils.c @@ -5,7 +5,20 @@ #include #include -bool mac_pton(const char *s, u8 *mac) +/** + * parse_mac_pton - convert a MAC address string using a custom delimiter + * @s: string to be parsed + * @mac: buffer to store the result, left untouched if @s is malformed + * @delim: characters accepted as a separator between the byte pairs + * + * @s must be at least MAC_ADDR_STR_LEN characters long and use a character + * from @delim at every separator position, e.g. "aa.bb:cc.dd:ee.ff" with + * ".:". Only the first MAC_ADDR_STR_LEN characters are checked; anything + * after them is ignored. + * + * Return: true on success, false if @s is malformed. + */ +bool parse_mac_pton(const char *s, u8 *mac, const char *delim) { int i; @@ -16,7 +29,7 @@ bool mac_pton(const char *s, u8 *mac) for (i = 0; i < ETH_ALEN; i++) { if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1])) return false; - if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':') + if (i != ETH_ALEN - 1 && !strchr(delim, s[i * 3 + 2])) return false; } for (i = 0; i < ETH_ALEN; i++) { @@ -24,4 +37,4 @@ bool mac_pton(const char *s, u8 *mac) } return true; } -EXPORT_SYMBOL(mac_pton); +EXPORT_SYMBOL(parse_mac_pton); -- 2.50.1