mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Konrad Gräfe" <k.graefe@gateware.de>
To: Quentin Schulz <quentin.schulz@theobroma-systems.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Cc: "Konrad Gräfe" <k.graefe@gateware.de>, stable@vger.kernel.org
Subject: [PATCH v4 1/2] vsprintf: Add %p[mM]U for uppercase MAC address
Date: Fri, 28 Apr 2023 08:49:04 +0200	[thread overview]
Message-ID: <20230428064905.145858-1-k.graefe@gateware.de> (raw)
In-Reply-To: <20230427115120.241954-2-k.graefe@gateware.de>

The CDC-ECM specification requires an USB gadget to send the host MAC
address as uppercase hex string. This change adds the appropriate
modifier.

Cc: stable@vger.kernel.org
Signed-off-by: Konrad Gräfe <k.graefe@gateware.de>
---

Changes since v3:
* Added documentation
* Added test cases
* Use string_upper() after conversion to simplify conversion loop
* Fixed maybe-uninitalized variable warning

Added in v3

 Documentation/core-api/printk-formats.rst | 15 ++++++++++-----
 lib/test_printf.c                         |  2 ++
 lib/vsprintf.c                            |  5 +++++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index dbe1aacc79d0..1ec682bdfe94 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -298,11 +298,13 @@ MAC/FDDI addresses
 
 ::
 
-	%pM	00:01:02:03:04:05
-	%pMR	05:04:03:02:01:00
-	%pMF	00-01-02-03-04-05
-	%pm	000102030405
-	%pmR	050403020100
+	%pM	00:01:02:03:aa:bb
+	%pMR	aa:bb:03:02:01:00
+	%pMF	00-01-02-03-aa-bb
+	%pMU	00:01:02:03:AA:BB
+	%pm	00010203aabb
+	%pmR	bbaa03020100
+	%pmU	00010203AABB
 
 For printing 6-byte MAC/FDDI addresses in hex notation. The ``M`` and ``m``
 specifiers result in a printed address with (M) or without (m) byte
@@ -316,6 +318,9 @@ For Bluetooth addresses the ``R`` specifier shall be used after the ``M``
 specifier to use reversed byte order suitable for visual interpretation
 of Bluetooth addresses which are in the little endian order.
 
+For uppercase hex notation the ``U`` specifier shall be used after the ``M``
+and ``m`` specifiers.
+
 Passed by reference.
 
 IPv4 addresses
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 46b4e6c414a3..7f4de2ecafbc 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -416,9 +416,11 @@ mac(void)
 	const u8 addr[6] = {0x2d, 0x48, 0xd6, 0xfc, 0x7a, 0x05};
 
 	test("2d:48:d6:fc:7a:05", "%pM", addr);
+	test("2D:48:D6:FC:7A:05", "%pMU", addr);
 	test("05:7a:fc:d6:48:2d", "%pMR", addr);
 	test("2d-48-d6-fc-7a-05", "%pMF", addr);
 	test("2d48d6fc7a05", "%pm", addr);
+	test("2D48D6FC7A05", "%pmU", addr);
 	test("057afcd6482d", "%pmR", addr);
 }
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index be71a03c936a..c82616c335e0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1301,6 +1301,9 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 	}
 	*p = '\0';
 
+	if (fmt[1] == 'U')
+		string_upper(mac_addr, mac_addr);
+
 	return string_nocheck(buf, end, mac_addr, spec);
 }
 
@@ -2280,6 +2283,7 @@ char *rust_fmt_argument(char *buf, char *end, void *ptr);
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
  * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
+ * - '[mM]U' For a 6-byte MAC address in uppercase hex
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -2407,6 +2411,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
 					/* [mM]F (FDDI) */
+					/* [mM]U (Uppercase hex) */
 					/* [mM]R (Reverse order; Bluetooth) */
 		return mac_address_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
-- 
2.34.1


  reply	other threads:[~2023-04-28  6:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2023042625-rendition-distort-fe06@gregkh>
2023-04-27 11:51 ` [PATCH v3 " Konrad Gräfe
2023-04-27 11:51   ` [PATCH v3 2/2] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-28  6:49     ` Konrad Gräfe [this message]
2023-04-28  6:49       ` [PATCH v4 " Konrad Gräfe
2023-05-02 20:03       ` [PATCH v4 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Andy Shevchenko
2023-05-05 14:36     ` [PATCH v5] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-27 12:26   ` [PATCH v3 1/2] vsprintf: Add %p[mM]U for uppercase MAC address Greg Kroah-Hartman
2023-04-27 12:35   ` Rasmus Villemoes
2023-04-27 14:26     ` Konrad Gräfe
2023-04-27 21:30     ` Peter Seiderer
2023-04-28  6:56   ` Rasmus Villemoes
2023-04-28  7:19     ` Greg Kroah-Hartman
2023-04-28  7:46     ` David Laight
2023-05-02 20:01       ` Andy Shevchenko
2023-05-02 12:23     ` Petr Mladek
2023-05-04 13:25       ` Konrad Gräfe

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=20230428064905.145858-1-k.graefe@gateware.de \
    --to=k.graefe@gateware.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andrzej.p@collabora.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=stable@vger.kernel.org \
    /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®