* [PATCH v2 0/2] vsprintf: add upper case to %p[mM] et alia
@ 2026-06-03 10:34 Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 1/2] vsprintf: Add upper case flavour to %p[mM] Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-06-03 10:34 UTC (permalink / raw)
To: Andy Shevchenko, Jiri Kosina, Daniel J. Ogorchock, Petr Mladek,
Tamir Duberstein, linux-doc, linux-kernel, linux-input
Cc: Steven Rostedt, Rasmus Villemoes, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Benjamin Tissoires, Andrew Morton
The first patch induced by Sashiko rightfully rises a concern on
potential ABI breakage. To avoid that and allow the user (patch 2)
to be converted to use unified output introduce %p[mM][...]U for
printing in upper case. Tests are included and passed.
Changelog v2:
- added first patch (Sashiko)
Andy Shevchenko (2):
vsprintf: Add upper case flavour to %p[mM]
HID: nintendo: Use %pM format specifier for MAC addresses
Documentation/core-api/printk-formats.rst | 3 +++
drivers/hid/hid-nintendo.c | 10 ++--------
lib/tests/printf_kunit.c | 2 ++
lib/vsprintf.c | 22 ++++++++++++++++------
4 files changed, 23 insertions(+), 14 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] vsprintf: Add upper case flavour to %p[mM]
2026-06-03 10:34 [PATCH v2 0/2] vsprintf: add upper case to %p[mM] et alia Andy Shevchenko
@ 2026-06-03 10:34 ` Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-06-03 10:34 UTC (permalink / raw)
To: Andy Shevchenko, Jiri Kosina, Daniel J. Ogorchock, Petr Mladek,
Tamir Duberstein, linux-doc, linux-kernel, linux-input
Cc: Steven Rostedt, Rasmus Villemoes, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Benjamin Tissoires, Andrew Morton
Some of the (ABI aware) code needs an upper case when printing MAC
addresses. Introduce an extension for that into the existing %p[mM].
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
Documentation/core-api/printk-formats.rst | 3 +++
lib/tests/printf_kunit.c | 2 ++
lib/vsprintf.c | 22 ++++++++++++++++------
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index c0b1b6089307..57e887ff24bc 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -322,6 +322,7 @@ MAC/FDDI addresses
%pMF 00-01-02-03-04-05
%pm 000102030405
%pmR 050403020100
+ %p[mM][FR][U]
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
@@ -335,6 +336,8 @@ 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.
+When ``U`` is passed, the result is printed in the upper case.
+
Passed by reference.
IPv4 addresses
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index 58e639b01e83..eccf041ebd56 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -435,8 +435,10 @@ mac(struct kunit *kunittest)
test("2d:48:d6:fc:7a:05", "%pM", addr);
test("05:7a:fc:d6:48:2d", "%pMR", addr);
+ test("05:7A:FC:D6:48:2D", "%pMRU", 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 1389b50266bf..c9b6ec0f0de6 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1303,31 +1303,39 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
char *p = mac_addr;
int i;
- char separator;
+ char separator = ':';
bool reversed = false;
+ bool uc = false;
if (check_pointer(&buf, end, addr, spec))
return buf;
switch (fmt[1]) {
case 'F':
+ uc = fmt[2] == 'U';
separator = '-';
break;
case 'R':
+ uc = fmt[2] == 'U';
reversed = true;
- fallthrough;
+ break;
+
+ case 'U':
+ uc = true;
+ break;
default:
- separator = ':';
break;
}
for (i = 0; i < 6; i++) {
- if (reversed)
- p = hex_byte_pack(p, addr[5 - i]);
+ u8 byte = reversed ? addr[5 - i] : addr[i];
+
+ if (uc)
+ p = hex_byte_pack_upper(p, byte);
else
- p = hex_byte_pack(p, addr[i]);
+ p = hex_byte_pack(p, byte);
if (fmt[0] == 'M' && i != 5)
*p++ = separator;
@@ -2410,6 +2418,7 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
* - '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][FR][U]' One of the above in the upper case
* - '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
@@ -2544,6 +2553,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'm': /* Contiguous: 000102030405 */
/* [mM]F (FDDI) */
/* [mM]R (Reverse order; Bluetooth) */
+ /* [mM][FR][U] (One of the above in the upper case) */
return mac_address_string(buf, end, ptr, spec, fmt);
case 'I': /* Formatted IP supported
* 4: 1.2.3.4
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses
2026-06-03 10:34 [PATCH v2 0/2] vsprintf: add upper case to %p[mM] et alia Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 1/2] vsprintf: Add upper case flavour to %p[mM] Andy Shevchenko
@ 2026-06-03 10:34 ` Andy Shevchenko
2026-06-03 12:03 ` Benjamin Tissoires
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-06-03 10:34 UTC (permalink / raw)
To: Andy Shevchenko, Jiri Kosina, Daniel J. Ogorchock, Petr Mladek,
Tamir Duberstein, linux-doc, linux-kernel, linux-input
Cc: Steven Rostedt, Rasmus Villemoes, Sergey Senozhatsky,
Jonathan Corbet, Shuah Khan, Benjamin Tissoires, Andrew Morton
Convert to %pM instead of using custom code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/hid/hid-nintendo.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 29008c2cc530..05c50f2530ef 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -2431,14 +2431,8 @@ static int joycon_read_info(struct joycon_ctlr *ctlr)
for (i = 4, j = 0; j < 6; i++, j++)
ctlr->mac_addr[j] = report->subcmd_reply.data[i];
- ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL,
- "%02X:%02X:%02X:%02X:%02X:%02X",
- ctlr->mac_addr[0],
- ctlr->mac_addr[1],
- ctlr->mac_addr[2],
- ctlr->mac_addr[3],
- ctlr->mac_addr[4],
- ctlr->mac_addr[5]);
+ ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL, "%pMU",
+ ctlr->mac_addr);
if (!ctlr->mac_addr_str)
return -ENOMEM;
hid_info(ctlr->hdev, "controller MAC = %s\n", ctlr->mac_addr_str);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses
2026-06-03 10:34 ` [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses Andy Shevchenko
@ 2026-06-03 12:03 ` Benjamin Tissoires
0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2026-06-03 12:03 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jiri Kosina, Daniel J. Ogorchock, Petr Mladek, Tamir Duberstein,
linux-doc, linux-kernel, linux-input, Steven Rostedt,
Rasmus Villemoes, Sergey Senozhatsky, Jonathan Corbet, Shuah Khan,
Andrew Morton
On Jun 03 2026, Andy Shevchenko wrote:
> Convert to %pM instead of using custom code.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Not sure where the first patch should land, so in case someone prefers
having the full series through their tree:
Acked-by: Benjamin Tissoires <bentiss@kernel.org>
Cheers,
Benjamin
> ---
> drivers/hid/hid-nintendo.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
> index 29008c2cc530..05c50f2530ef 100644
> --- a/drivers/hid/hid-nintendo.c
> +++ b/drivers/hid/hid-nintendo.c
> @@ -2431,14 +2431,8 @@ static int joycon_read_info(struct joycon_ctlr *ctlr)
> for (i = 4, j = 0; j < 6; i++, j++)
> ctlr->mac_addr[j] = report->subcmd_reply.data[i];
>
> - ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL,
> - "%02X:%02X:%02X:%02X:%02X:%02X",
> - ctlr->mac_addr[0],
> - ctlr->mac_addr[1],
> - ctlr->mac_addr[2],
> - ctlr->mac_addr[3],
> - ctlr->mac_addr[4],
> - ctlr->mac_addr[5]);
> + ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL, "%pMU",
> + ctlr->mac_addr);
> if (!ctlr->mac_addr_str)
> return -ENOMEM;
> hid_info(ctlr->hdev, "controller MAC = %s\n", ctlr->mac_addr_str);
> --
> 2.50.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-03 12:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 10:34 [PATCH v2 0/2] vsprintf: add upper case to %p[mM] et alia Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 1/2] vsprintf: Add upper case flavour to %p[mM] Andy Shevchenko
2026-06-03 10:34 ` [PATCH v2 2/2] HID: nintendo: Use %pM format specifier for MAC addresses Andy Shevchenko
2026-06-03 12:03 ` Benjamin Tissoires
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox