]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vsprintf: Add upper case flavour to %p[mM]
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 3 Jun 2026 10:34:02 +0000 (12:34 +0200)
committerPetr Mladek <pmladek@suse.com>
Fri, 12 Jun 2026 12:20:25 +0000 (14:20 +0200)
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>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://patch.msgid.link/20260603104351.152085-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Documentation/core-api/printk-formats.rst
lib/tests/printf_kunit.c
lib/vsprintf.c

index c0b1b6089307a38b6d7ef99940268d1ffce00716..57e887ff24bc8c6fd7c3bff6a0f1a17492935ccf 100644 (file)
@@ -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
index bb70b9cddadd8b9acc61aeb6a62a8f441266355f..6c7ce94383cff26e7d26332ac311dae68417bf5d 100644 (file)
@@ -415,8 +415,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);
 }
 
index 9f359b31c8d1c1805ffb62a57e5cd206740e3163..3f79fe6342b6e302b693dd44461ead94785bad26 100644 (file)
@@ -1309,31 +1309,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;
@@ -2416,6 +2424,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
@@ -2550,6 +2559,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