Skip to contentSkip to conversation

ice: devlink: use %*phD to print small buffer

PATCH In review Andy Shevchenko 4 participants 5 messages Jul 30, 2020 – Aug 1, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: devlink: use %*phD to print small buffer

Use %*phD format to print small buffer as hex string.

---
 drivers/net/ethernet/intel/ice/ice_devlink.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_devlink.c +1 -3
index dbbd8b6f9d1a..a9105ad5b983 100644
@@ -13,9 +13,7 @@ static int ice_info_get_dsn(struct ice_pf *pf, char *buf, size_t len)
 	/* Copy the DSN into an array in Big Endian format */
 	put_unaligned_be64(pci_get_dsn(pf->pdev), dsn);
 
-	snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
-		 dsn[0], dsn[1], dsn[2], dsn[3],
-		 dsn[4], dsn[5], dsn[6], dsn[7]);
+	snprintf(buf, len, "%8phD", dsn);
 
 	return 0;
 }
Signature · 1 line
2.27.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 3 lines · Andy Shevchenko

Use %*phD format to print small buffer as hex string.

Ah nice. I swear I looked for a printk format to do this and didn't find one. But it's been there since 2012.. so I guess I just missed it.

I also tested this on my system to make sure it gives the same output for the serial value, so I guess also:

Thanks!

Quoted 20 lines
---
 drivers/net/ethernet/intel/ice/ice_devlink.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_devlink.c +1 -3
index dbbd8b6f9d1a..a9105ad5b983 100644
@@ -13,9 +13,7 @@ static int ice_info_get_dsn(struct ice_pf *pf, char *buf, size_t len)
 	/* Copy the DSN into an array in Big Endian format */
 	put_unaligned_be64(pci_get_dsn(pf->pdev), dsn);
 
-	snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
-		 dsn[0], dsn[1], dsn[2], dsn[3],
-		 dsn[4], dsn[5], dsn[6], dsn[7]);
+	snprintf(buf, len, "%8phD", dsn);
 
 	return 0;
 }
#2 lore raw
Quoted 7 lines · Jacob Keller
Quoted 3 lines · Andy Shevchenko

Use %*phD format to print small buffer as hex string.

Ah nice. I swear I looked for a printk format to do this and didn't find one. But it's been there since 2012.. so I guess I just missed it.

commit 31550a16a5d2af859e8a11839e8c6c6c9c92dfa7

Author: Andy Shevchenko <[email protected]>
Date:   Mon Jul 30 14:40:27 2012 -0700

vsprintf: add support of '%*ph[CDN]'

Maybe it was just a coincidence :-)

Quoted 6 lines

I also tested this on my system to make sure it gives the same output for the serial value, so I guess also:

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko