print UUID/GUIDs with %pU
Subsystems (13)
cover print UUID/GUIDs with %pU
Perhaps UUIDs are common enough to use a %p extension
Joe Perches (3):
lib/vsprintf.c: Add %pU - ptr to a UUID/GUID
treewide: use %pU to print UUID/GUIDs drivers/staging/hv/: use %pU to print UUID/GUIDs
drivers/char/random.c | 10 +-- drivers/firmware/dmi_scan.c | 5 +- drivers/md/md.c | 16 +---- drivers/media/video/uvc/uvc_ctrl.c | 69 +++++++++----------- drivers/media/video/uvc/uvc_driver.c | 7 +- drivers/media/video/uvc/uvcvideo.h | 10 --- drivers/staging/hv/ChannelMgmt.c | 22 +------ drivers/staging/hv/vmbus_drv.c | 116 ++++------------------------------ fs/gfs2/sys.c | 16 +---- fs/ubifs/debug.c | 9 +-- fs/ubifs/super.c | 7 +-- fs/xfs/xfs_log_recover.c | 14 +--- include/linux/efi.h | 6 +-- lib/vsprintf.c | 58 +++++++++++++++++- 14 files changed, 125 insertions(+), 240 deletions(-)
PATCH 1/3 lib/vsprintf.c: Add %pU - ptr to a UUID/GUID
UUID/GUIDs are somewhat common in kernel source.
Standardize the printed style of UUID/GUIDs by using another extension to %p.
%pU: 01020304:0506:0708:090a:0b0c0d0e0f10
%pUr: 04030201:0605:0807:0a09:0b0c0d0e0f10
%pU[r]X:Use upper case hex
--- lib/vsprintf.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 57 insertions(+), 1 deletions(-)
lib/vsprintf.c +57 -1
@@ -790,6 +790,53 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,return string (buf, end, ip4_addr, spec); } +static char *uuid_string (char *buf,char *end,const u8 *addr, +struct printf_spec spec,const char *fmt) +{ +char uuid[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" )]; +char *p = uuid; +int i; +static const u8 r[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 }; +static const u8 n[16 ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 }; +const u8 *index = n; +bool uc = false; + +while (isalnum (*(++fmt))) { +switch (*fmt) { +case 'r' : + index = r; +break ; +case 'X' : + uc = true; +break ; + } + } + +for (i =0 ; i <16 ; i++) { + p =pack_hex_byte (p, addr[index[i]]); +switch (i) { +case 3 : +case 5 : +case 7 : +case 9 : + *p++ ='-' ; +break ; + } + } + + *p =0 ; + +if (uc) { + p = uuid; +while (*p) { + *p =toupper (*p); + p++; + } + } + +return string (buf, end, uuid, spec); +} +/* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format
@@ -814,6 +861,13 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,* IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) * - 'I6c' for IPv6 addresses printed as specified by * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt +* - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form +* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +* Options for %pU are: +* 'X' use upper case hex digits +* 'r' use LE byte order for U32 and U16s equivalents. Use indices: +* [3][2][1][0]-[5][4]-[7][6]-[9][8]-[10]...[15] +* * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 * function pointers are really function descriptors, which contain a * pointer to the real address.
@@ -828,9 +882,9 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,case 'F' :case 'f' : ptr =dereference_function_descriptor (ptr); -case 's' :/* Fallthrough */ case 'S' : +case 's' :return symbol_string (buf, end, ptr, spec, *fmt);case 'R' :return resource_string (buf, end, ptr, spec);
@@ -853,6 +907,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,return ip4_addr_string (buf, end, ptr, spec, fmt); }break ; +case 'U' : +return uuid_string (buf, end, ptr, spec, fmt); } spec.flags |=SMALL ;if (spec.field_width ==-1 ) {
Signature · 1 line
1.6.3.1.10.g659a0.dirty
Re: [PATCH 1/3] lib/vsprintf.c: Add %pU - ptr to a UUID/GUID
Hi Joe,
Quoted 6 lines · Joe Perches
UUID/GUIDs are somewhat common in kernel source.
Standardize the printed style of UUID/GUIDs by using another extension to %p.
%pU: 01020304:0506:0708:090a:0b0c0d0e0f10
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here
Quoted 1 line
%pUr: 04030201:0605:0807:0a09:0b0c0d0e0f10
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and here
Code does "01020304-0506-0708-090a-0b0c0d0e0f10".
This is not, what commit promises. Please change the commit message!
Best Regards
Ingo Oeser
Re: [PATCH 1/3] lib/vsprintf.c: Add %pU - ptr to a UUID/GUID
Quoted 1 line · Ingo Oeser
Hi Joe,
Hello Ingo.
Quoted 8 lines · Joe Perches
Quoted 5 lines
UUID/GUIDs are somewhat common in kernel source. Standardize the printed style of UUID/GUIDs by using another extension to %p.
%pU: 01020304:0506:0708:090a:0b0c0d0e0f10
%pUr: 04030201:0605:0807:0a09:0b0c0d0e0f10Code does "01020304-0506-0708-090a-0b0c0d0e0f10".
This is not, what commit promises. Please change the commit message!
True enough, that can change, no worries.
Does anyone have comments like:
1 what a stupid idea
2 how unnecessary
3 meh
4 bloat alert! linux is supposed to be lean
5 ok idea, bad implementation
6 sure, why not
Re: [PATCH 1/3] lib/vsprintf.c: Add %pU - ptr to a UUID/GUID
Quoted 16 lines · Joe Perches
Quoted 1 line · Ingo Oeser
Hi Joe,
Hello Ingo.
Quoted 8 lines · Joe Perches
Quoted 5 lines
UUID/GUIDs are somewhat common in kernel source. Standardize the printed style of UUID/GUIDs by using another extension to %p.
%pU: 01020304:0506:0708:090a:0b0c0d0e0f10
%pUr: 04030201:0605:0807:0a09:0b0c0d0e0f10Code does "01020304-0506-0708-090a-0b0c0d0e0f10".
This is not, what commit promises. Please change the commit message!True enough, that can change, no worries.
Quoted 8 lines
Does anyone have comments like:
1 what a stupid idea
2 how unnecessary
3 meh
4 bloat alert! linux is supposed to be lean
5 ok idea, bad implementation
6 sure, why not
Sure, why not :)
PATCH 2/3 treewide: use %pU to print UUID/GUIDs
In reply to Joe PerchesConverted individual GUID/UUID printing functions
to use the new %pU[Xr] in lib/vsprintf.c
--- drivers/char/random.c | 10 +--- drivers/firmware/dmi_scan.c | 5 +-- drivers/md/md.c | 16 ++------ drivers/media/video/uvc/uvc_ctrl.c | 69 ++++++++++++++++------------------ drivers/media/video/uvc/uvc_driver.c | 7 +-- drivers/media/video/uvc/uvcvideo.h | 10 ----- fs/gfs2/sys.c | 16 +------ fs/ubifs/debug.c | 9 +--- fs/ubifs/super.c | 7 +--- fs/xfs/xfs_log_recover.c | 14 ++----- include/linux/efi.h | 6 +-- 11 files changed, 54 insertions(+), 115 deletions(-)
drivers/char/random.c +3 -7
@@ -1245,12 +1245,8 @@ static int proc_do_uuid(ctl_table *table, int write,if (uuid[8 ] ==0 )generate_random_uuid (uuid); -sprintf (buf,"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" -"%02x%02x%02x%02x%02x%02x" , - uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ], - uuid[4 ], uuid[5 ], uuid[6 ], uuid[7 ], - uuid[8 ], uuid[9 ], uuid[10 ], uuid[11 ], - uuid[12 ], uuid[13 ], uuid[14 ], uuid[15 ]); +sprintf (buf,"%pU" , uuid); + fake_table.data = buf; fake_table.maxlen =sizeof (buf);
@@ -1350,7 +1346,7 @@ ctl_table random_table[] = {/******************************************************************** * -* Random funtions for networking +* Random functions for networking * ********************************************************************/
drivers/firmware/dmi_scan.c +1 -4
@@ -169,10 +169,7 @@ static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int indeif (!s)return ; -sprintf (s, -"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X" , - d[0 ], d[1 ], d[2 ], d[3 ], d[4 ], d[5 ], d[6 ], d[7 ], - d[8 ], d[9 ], d[10 ], d[11 ], d[12 ], d[13 ], d[14 ], d[15 ]); +sprintf (s,"%pUX" , d); dmi_ident[slot] = s; }
drivers/md/md.c +4 -12
@@ -1813,15 +1813,11 @@ static void print_sb_1(struct mdp_superblock_1 *sb) uuid = sb->set_uuid;printk (KERN_INFO -"md: SB: (V:%u) (F:0x%08x) Array-ID:<%02x%02x%02x%02x" -":%02x%02x:%02x%02x:%02x%02x:%02x%02x%02x%02x%02x%02x>\n" +"md: SB: (V:%u) (F:0x%08x) Array-ID:<%pU>\n" "md: Name: \"%s\" CT:%llu\n" ,le32_to_cpu (sb->major_version),le32_to_cpu (sb->feature_map), - uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ], - uuid[4 ], uuid[5 ], uuid[6 ], uuid[7 ], - uuid[8 ], uuid[9 ], uuid[10 ], uuid[11 ], - uuid[12 ], uuid[13 ], uuid[14 ], uuid[15 ], + uuid, sb->set_name, (unsigned long long )le64_to_cpu (sb->ctime) &MD_SUPERBLOCK_1_TIME_SEC_MASK );
@@ -1830,8 +1826,7 @@ static void print_sb_1(struct mdp_superblock_1 *sb) printk(KERN_INFO "md: L%u SZ%llu RD:%u LO:%u CS:%u DO:%llu DS:%llu SO:%llu" " RO:%llu\n" - "md: Dev:%08x UUID: %02x%02x%02x%02x:%02x%02x:%02x%02x:%02x%02x" - ":%02x%02x%02x%02x%02x%02x\n" + "md: Dev:%08x UUID: %pU\n" "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n" "md: (MaxDev:%u) \n", le32_to_cpu(sb->level),
@@ -1844,10 +1839,7 @@ static void print_sb_1(struct mdp_superblock_1 *sb) (unsigned long long )le64_to_cpu (sb->super_offset), (unsigned long long )le64_to_cpu (sb->recovery_offset),le32_to_cpu (sb->dev_number), - uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ], - uuid[4 ], uuid[5 ], uuid[6 ], uuid[7 ], - uuid[8 ], uuid[9 ], uuid[10 ], uuid[11 ], - uuid[12 ], uuid[13 ], uuid[14 ], uuid[15 ], + uuid, sb->devflags, (unsigned long long )le64_to_cpu (sb->utime) &MD_SUPERBLOCK_1_TIME_SEC_MASK , (unsigned long long)le64_to_cpu(sb->events),
drivers/media/video/uvc/uvc_ctrl.c +32 -37
131 lines not on this page · raw message
drivers/media/video/uvc/uvc_driver.c +3 -4
@@ -328,11 +328,10 @@ static int uvc_parse_format(struct uvc_device *dev, sizeof format->name); format->fcc = fmtdesc->fcc; }else { -uvc_printk (KERN_INFO ,"Unknown video format " -UVC_GUID_FORMAT "\n" , -UVC_GUID_ARGS (&buffer[5 ])); +uvc_printk (KERN_INFO ,"Unknown video format %pUr\n" , + &buffer[5 ]);snprintf (format->name,sizeof format->name, -UVC_GUID_FORMAT ,UVC_GUID_ARGS (&buffer[5 ])); +"%pUr" , &Buffer[5 ]); format->fcc =0 ; }
drivers/media/video/uvc/uvcvideo.h +0 -10
@@ -555,16 +555,6 @@ extern unsigned int uvc_trace_param; #define uvc_printk(level, msg...) \ printk(level "uvcvideo: " msg) -#define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \ - "%02x%02x%02x%02x%02x%02x" -#define UVC_GUID_ARGS (guid) \ - (guid)[3], (guid)[2], (guid)[1], (guid)[0], \ - (guid)[5], (guid)[4], \ - (guid)[7], (guid)[6], \ - (guid)[8], (guid)[9], \ - (guid)[10], (guid)[11], (guid)[12], \ - (guid)[13], (guid)[14], (guid)[15] -/* -------------------------------------------------------------------------- * Internal functions. */
fs/gfs2/sys.c +3 -13
@@ -85,11 +85,7 @@ static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf) buf[0 ] ='\0' ;if (!gfs2_uuid_valid (uuid))return 0 ; -return snprintf (buf,PAGE_SIZE ,"%02X%02X%02X%02X-%02X%02X-" -"%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n" , - uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ], uuid[4 ], uuid[5 ], - uuid[6 ], uuid[7 ], uuid[8 ], uuid[9 ], uuid[10 ], uuid[11 ], - uuid[12 ], uuid[13 ], uuid[14 ], uuid[15 ]); +return snprintf (buf,PAGE_SIZE ,"%pUX\n" , uuid); }static ssize_t freeze_show (struct gfs2_sbd *sdp,char *buf)
@@ -573,14 +569,8 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,add_uevent_var (env,"LOCKPROTO=%s" , sdp->sd_proto_name);if (!sdp->sd_args.ar_spectator)add_uevent_var (env,"JOURNALID=%u" , sdp->sd_lockstruct.ls_jid); -if (gfs2_uuid_valid (uuid)) { -add_uevent_var (env,"UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-" -"%02X%02X-%02X%02X%02X%02X%02X%02X" , - uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ], uuid[4 ], - uuid[5 ], uuid[6 ], uuid[7 ], uuid[8 ], uuid[9 ], - uuid[10 ], uuid[11 ], uuid[12 ], uuid[13 ], - uuid[14 ], uuid[15 ]); - } +if (gfs2_uuid_valid (uuid)) +add_uevent_var (env,"UUID=%pUX" , uuid);return 0 ; }
fs/ubifs/debug.c +2 -7
@@ -350,13 +350,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node) le32_to_cpu(sup->fmt_version));printk (KERN_DEBUG "\ttime_gran %u\n" ,le32_to_cpu (sup->time_gran)); -printk (KERN_DEBUG "\tUUID %02X%02X%02X%02X-%02X%02X" -"-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n" , - sup->uuid[0 ], sup->uuid[1 ], sup->uuid[2 ], sup->uuid[3 ], - sup->uuid[4 ], sup->uuid[5 ], sup->uuid[6 ], sup->uuid[7 ], - sup->uuid[8 ], sup->uuid[9 ], sup->uuid[10 ], sup->uuid[11 ], - sup->uuid[12 ], sup->uuid[13 ], sup->uuid[14 ], - sup->uuid[15 ]); +printk (KERN_DEBUG "\tUUID %pUX\n" , + sup->uuid);break ; }case UBIFS_MST_NODE :
fs/ubifs/super.c +1 -6
@@ -1393,12 +1393,7 @@ static int mount_ubifs(struct ubifs_info *c) c->leb_size, c->leb_size >> 10);dbg_msg ("data journal heads: %d" , c->jhead_cnt -NONDATA_JHEADS_CNT ); -dbg_msg ("UUID: %02X%02X%02X%02X-%02X%02X" -"-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X" , - c->uuid[0 ], c->uuid[1 ], c->uuid[2 ], c->uuid[3 ], - c->uuid[4 ], c->uuid[5 ], c->uuid[6 ], c->uuid[7 ], - c->uuid[8 ], c->uuid[9 ], c->uuid[10 ], c->uuid[11 ], - c->uuid[12 ], c->uuid[13 ], c->uuid[14 ], c->uuid[15 ]); +dbg_msg ("UUID: %pUX" , c->uuid);dbg_msg ("big_lpt %d" , c->big_lpt);dbg_msg ("log LEBs: %d (%d - %d)" , c->log_lebs,UBIFS_LOG_LNUM , c->log_last);
fs/xfs/xfs_log_recover.c +4 -10
@@ -225,16 +225,10 @@ xlog_header_check_dump( xfs_mount_t *mp, xlog_rec_header_t *head) { -int b; - -cmn_err (CE_DEBUG ,"%s: SB : uuid = " , __func__); -for (b =0 ; b <16 ; b++) -cmn_err (CE_DEBUG ,"%02x" , ((__uint8_t *)&mp->m_sb.sb_uuid)[b]); -cmn_err (CE_DEBUG ,", fmt = %d\n" ,XLOG_FMT ); -cmn_err (CE_DEBUG ," log : uuid = " ); -for (b =0 ; b <16 ; b++) -cmn_err (CE_DEBUG ,"%02x" , ((__uint8_t *)&head->h_fs_uuid)[b]); -cmn_err (CE_DEBUG ,", fmt = %d\n" ,be32_to_cpu (head->h_fmt)); +cmn_err (CE_DEBUG ,"%s: SB : uuid = %pU, fmt = %d\n" , + __func__, &mp->m_sb.sb_uuid,XLOG_FMT ); +cmn_err (CE_DEBUG ," log : uuid = %pU, fmt = %d\n" , + &head->h_fs_uuid,be32_to_cpu (head->h_fmt)); }#else #define xlog_header_check_dump (mp, head)
include/linux/efi.h +1 -5
@@ -280,11 +280,7 @@ efi_guidcmp (efi_guid_t left, efi_guid_t right)static inline char *efi_guid_unparse (efi_guid_t *guid,char *out) { -sprintf (out,"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" , - guid->b[3 ], guid->b[2 ], guid->b[1 ], guid->b[0 ], - guid->b[5 ], guid->b[4 ], guid->b[7 ], guid->b[6 ], - guid->b[8 ], guid->b[9 ], guid->b[10 ], guid->b[11 ], - guid->b[12 ], guid->b[13 ], guid->b[14 ], guid->b[15 ]); +sprintf (out,"%pUr" , guid->b);return out; }
Signature · 1 line
1.6.3.1.10.g659a0.dirty
PATCH 3/3 drivers/staging/hv/: use %pU to print UUID/GUIDs
In reply to Joe PerchesConverted individual GUID/UUID printing functions
to use the new %pU[Xr] in lib/vsprintf.c
--- drivers/staging/hv/ChannelMgmt.c | 22 +------- drivers/staging/hv/vmbus_drv.c | 116 ++++---------------------------------- 2 files changed, 14 insertions(+), 124 deletions(-)
drivers/staging/hv/ChannelMgmt.c +2 -20
@@ -263,28 +263,10 @@ static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr)DPRINT_INFO (VMBUS ,"Channel offer notification - " "child relid %d monitor id %d allocated %d, " -"type {%02x%02x%02x%02x-%02x%02x-%02x%02x-" -"%02x%02x%02x%02x%02x%02x%02x%02x} " -"instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-" -"%02x%02x%02x%02x%02x%02x%02x%02x}" , +"type {%pUr} instance {%pUr}" , offer->ChildRelId, offer->MonitorId, offer->MonitorAllocated, - guidType->data[3 ], guidType->data[2 ], - guidType->data[1 ], guidType->data[0 ], - guidType->data[5 ], guidType->data[4 ], - guidType->data[7 ], guidType->data[6 ], - guidType->data[8 ], guidType->data[9 ], - guidType->data[10 ], guidType->data[11 ], - guidType->data[12 ], guidType->data[13 ], - guidType->data[14 ], guidType->data[15 ], - guidInstance->data[3 ], guidInstance->data[2 ], - guidInstance->data[1 ], guidInstance->data[0 ], - guidInstance->data[5 ], guidInstance->data[4 ], - guidInstance->data[7 ], guidInstance->data[6 ], - guidInstance->data[8 ], guidInstance->data[9 ], - guidInstance->data[10 ], guidInstance->data[11 ], - guidInstance->data[12 ], guidInstance->data[13 ], - guidInstance->data[14 ], guidInstance->data[15 ]); + guidType->data, guidInstance->data);/* Allocate the channel object and save this offer. */ newChannel =AllocVmbusChannel ();
drivers/staging/hv/vmbus_drv.c +12 -104
143 lines not on this page · raw message
Signature · 1 line
1.6.3.1.10.g659a0.dirty