Skip to contentSkip to conversation

wireless: at76c50x: fix multithread access to hex2str

PATCH In review Andy Shevchenko 9 participants 32 messages Sep 28, 2011 – Sep 11, 2012

Subsystems (4)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 wireless: at76c50x: fix multithread access to hex2str

The original hex2str uses finite array of buffers to keep output data. It's a wrong approach, because we can't say at compile time how many threads will be used.

This patch introduces one buffer and global mutex to access this function. All calls of it are wrapped by locking this mutex. It saves some memory as a side effect.

Cc "John W. Linville" <[email protected]>
---
 drivers/net/wireless/at76c50x-usb.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
drivers/net/wireless/at76c50x-usb.c +19 -4
index 39322d4..af043f6 100644
@@ -498,15 +498,14 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
 #define HEX2STR_MAX_LEN 64
 
+static DEFINE_MUTEX(hex2str_mutex);
+
 /* Convert binary data into hex string */
 static char *hex2str(void *buf, size_t len)
 {
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
+	static char ret[3 * HEX2STR_MAX_LEN + 1];
 	char *obuf = ret;
 	u8 *ibuf = buf;
 
@@ -1003,10 +1002,13 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	key_len = (m->encryption_level == 1) ?
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
+	mutex_lock(&hex2str_mutex);
 	for (i = 0; i < WEP_KEYS; i++)
 		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
 			 wiphy_name(priv->hw->wiphy), i,
 			 hex2str(m->wep_default_keyvalue[i], key_len));
+	mutex_unlock(&hex2str_mutex);
+
 exit:
 	kfree(m);
 }
@@ -1028,6 +1030,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		goto exit;
 	}
 
+	mutex_lock(&hex2str_mutex);
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
@@ -1045,6 +1048,8 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
+	mutex_unlock(&hex2str_mutex);
+
 exit:
 	kfree(m);
 }
@@ -1064,6 +1069,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		goto exit;
 	}
 
+	mutex_lock(&hex2str_mutex);
 	at76_dbg(DBG_MIB, "%s: MIB MAC: max_tx_msdu_lifetime %d "
 		 "max_rx_lifetime %d frag_threshold %d rts_threshold %d "
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
@@ -1082,6 +1088,8 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->listen_interval),
 		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
 		 m->desired_bssid, m->desired_bsstype);
+	mutex_unlock(&hex2str_mutex);
+
 exit:
 	kfree(m);
 }
@@ -1160,6 +1168,8 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
+	mutex_lock(&hex2str_mutex);
+
 	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
 		 wiphy_name(priv->hw->wiphy),
 		 hex2str(m->channel_list, sizeof(m->channel_list)));
@@ -1167,6 +1177,8 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
 		 wiphy_name(priv->hw->wiphy),
 		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+
+	mutex_unlock(&hex2str_mutex);
 exit:
 	kfree(m);
 }
@@ -1368,6 +1380,7 @@ static int at76_startup_device(struct at76_priv *priv)
 	struct at76_card_config *ccfg = &priv->card_config;
 	int ret;
 
+	mutex_lock(&hex2str_mutex);
 	at76_dbg(DBG_PARAMS,
 		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
@@ -1375,6 +1388,8 @@ static int at76_startup_device(struct at76_priv *priv)
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
+	mutex_unlock(&hex2str_mutex);
+
 	at76_dbg(DBG_PARAMS,
 		 "%s param: preamble %s rts %d retry %d frag %d "
 		 "txrate %s auth_mode %d", wiphy_name(priv->hw->wiphy),
Signature · 1 line
1.7.6.3
#1 lore raw
Quoted 10 lines · On Wed, 28 Sep 2011 16:17:31 +0300 Andy Shevchenko…

The original hex2str uses finite array of buffers to keep output data. It's a wrong approach, because we can't say at compile time how many threads will be used.

This patch introduces one buffer and global mutex to access this function. All calls of it are wrapped by locking this mutex. It saves some memory as a side effect.

Cc "John W. Linville" <[email protected]>

The reason for having 4 buffers is to allow using hex2str() more than once in the same printk() statement. As you can see, hex2str() is never used in one statement more than once. Your solution would make it impossible to use hex2str() twice in the same printk(), as the buffer would be reused. Actually, wrong data would be printed with no warning! Such code doesn't exist in the driver, but it could be added by somebody looking for a problem. And that would hamper debugging instead of helping it.

I think we can live with a debug function printing wrong data if it's called by 5 callers at once.

And if you want a perfectly correct fix, I suggest that you use buffers allocated by the callers on the stack. That's less intrusive than mutexes, and it would allow using more than one hex2str() in one statement as long as the buffers are different.

Or maybe hex2str() should be replaced with calls to print_hex_dump_bytes()? That would add extra lines to the kernel output, but it's no big deal. Of course, if you are concerned about 5 callers printing bytes in the same time, the output may be hard to understand, but I don't think it a problem that needs addressing.

Or maybe you could develop an extension for printk() format that would dump strings of the given length? Something like %pM, but with an extra argument (and make sure it would not trigger a gcc warning). This way, everybody would benefit.

Please rethink whether it's helpful to send such "fixes" for old and little maintained drivers. There are few people who can work on them, and they have little time for the old drivers. Their time is better spent fixing real problems than reviewing untested or badly conceived patches for imaginary problems and style issues. Besides, there are few users who could test the driver and report breakage.

Signature · 2 lines
Regards,
Pavel Roskin
author reviewer
#2 lore raw
Quoted 11 lines · Pavel Roskin
Quoted 8 lines · On Wed, 28 Sep 2011 16:17:31 +0300 Andy Shevchenko…

The original hex2str uses finite array of buffers to keep output data. It's a wrong approach, because we can't say at compile time how many threads will be used.

This patch introduces one buffer and global mutex to access this function. All calls of it are wrapped by locking this mutex. It saves some memory as a side effect.

Quoted 5 lines
Quoted 2 lines
Cc "John W. Linville" <[email protected]>

The reason for having 4 buffers is to allow using hex2str() more than once in the same printk() statement.

And even in this case it has a weird limitation. Why 4? Why not 5 or 20?

Quoted 1 line

As you can see, hex2str() is never used in one statement more than once.

Yeah, that's why it works in both cases.

Quoted 6 lines

Your solution would make
it impossible to use hex2str() twice in the same printk(), as the buffer would be reused. Actually, wrong data would be printed with no warning! Such code doesn't exist in the driver, but it could be added by somebody looking for a problem. And that would hamper debugging instead of helping it.

You know, there is no statement, how to use the function for the 3rd party developer. We have the mailing list not only for bots. I'm glad to hear some explanations which I didn't catch from the code itself.

Quoted 2 lines

I think we can live with a debug function printing wrong data if it's called by 5 callers at once.

I disagree with such attitude.

Quoted 5 lines

And if you want a perfectly correct fix, I suggest that you use buffers allocated by the callers on the stack. That's less intrusive than mutexes, and it would allow using more than one hex2str() in one statement as long as the buffers are different.
Or maybe hex2str() should be replaced with calls to print_hex_dump_bytes()?

I thought about it. Actually I must write RFC prefix to the patch, my bad.

Quoted 4 lines

Or maybe you could develop an extension for printk() format that would dump strings of the given length? Something like %pM, but with an extra argument (and make sure it would not trigger a gcc warning). This way, everybody would benefit.

I don't think it would be a noticeable benefit. On the other hand vsnprintf() is hugely overloaded by many "extensions" to the C99 variant.

Quoted 2 lines

Please rethink whether it's helpful to send such "fixes" for old and little maintained drivers.

Last copyright is 2010, TODO list actually suggests to remove hex2str at all.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#3 lore raw
Quoted 8 lines · On Thu, 29 Sep 2011 13:46:55 +0300 Andy Shevchenko…
Quoted 4 lines · Pavel Roskin

Or maybe you could develop an extension for printk() format that would dump strings of the given length? Something like %pM, but with an extra argument (and make sure it would not trigger a gcc warning). This way, everybody would benefit.

I don't think it would be a noticeable benefit. On the other hand vsnprintf() is hugely overloaded by many "extensions" to the C99 variant.

I looked at the code, and it seems very little is needed to support "%*pM"

Quoted 4 lines
Quoted 2 lines

Please rethink whether it's helpful to send such "fixes" for old and little maintained drivers.

Last copyright is 2010, TODO list actually suggests to remove hex2str at all.

I don't know where it's written, but I think it's a good idea, especially if there is a better alternative available for all drivers.

Signature · 2 lines
Regards,
Pavel Roskin
author reviewer
#4 lore raw

RFC PATCH 1/2 lib: printf: append support of '%*p[Mm][FR]'

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef
---
 lib/vsprintf.c |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
lib/vsprintf.c +13 -9
index a0b5f15..1645d7e 100644
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-			 struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)
 {
-	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
-	char *p = mac_addr;
+	char hex_str[64*3];	/* support up to 64 bytes to print */
+	int len = 6;		/* default length is 6 bytes */
+	char *p = hex_str;
 	int i;
 	char separator;
 	bool reversed = false;
@@ -678,18 +679,21 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 		break;
 	}
 
-	for (i = 0; i < 6; i++) {
+	if (spec.field_width > 0)
+		len = min_t(int, spec.field_width, 64);
+
+	for (i = 0; i < len; i++) {
 		if (reversed)
-			p = hex_byte_pack(p, addr[5 - i]);
+			p = hex_byte_pack(p, addr[len - 1 - i]);
 		else
 			p = hex_byte_pack(p, addr[i]);
 
-		if (fmt[0] == 'M' && i != 5)
+		if (fmt[0] == 'M' && i != len - 1)
 			*p++ = separator;
 	}
 	*p = '\0';
 
-	return string(buf, end, mac_addr, spec);
+	return string(buf, end, hex_str, spec);
 }
 
 static noinline_for_stack
@@ -1011,7 +1015,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	case 'm':			/* Contiguous: 000102030405 */
 					/* [mM]F (FDDI) */
 					/* [mM]R (Reverse order; Bluetooth) */
-		return mac_address_string(buf, end, ptr, spec, fmt);
+		return hex_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
 					 * 4:	1.2.3.4
 					 * 6:	0001:0203:...:0708
Signature · 1 line
1.7.10
author reviewer
#5 lore raw

RFC PATCH 2/2 wireless: at76c50x: eliminate hex2str()

The hex2str() is substituted by '%*pMF' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index efc162e..f82f76b 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*pMF",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*pMF current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*pMF desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*pMF",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*pMF",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*pMF) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 1 line
1.7.10
#6 lore raw

Re: [RFC][PATCH 2/2] wireless: at76c50x: eliminate hex2str()

Quoted 117 lines · Andy Shevchenko

The hex2str() is substituted by '%*pMF' specificator.

---
  drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
  1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +10 -40
index efc162e..f82f76b 100644
@@ -498,36 +498,6 @@ exit:
  	return ret;
  }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
  /* LED trigger */
  static int tx_activity;
  static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
  	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
  	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*pMF",
  			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
  exit:
  	kfree(m);
  }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
  	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
  		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
  		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*pMF current_bss_type %d "
  		 "pm_mode %d ibss_change %d res %d "
  		 "multi_domain_capability_implemented %d "
  		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
  		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
  		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
  		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
  		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
  		 m->res, m->multi_domain_capability_implemented,
  		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
  		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
  		 "scan_type %d scan_channel %d probe_delay %u "
  		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*pMF desired_bssid %pM desired_bsstype %d",
  		 wiphy_name(priv->hw->wiphy),
  		 le32_to_cpu(m->max_tx_msdu_lifetime),
  		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
  		 le16_to_cpu(m->min_channel_time),
  		 le16_to_cpu(m->max_channel_time),
  		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
  		 m->desired_bssid, m->desired_bsstype);
  exit:
  	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
  		goto exit;
  	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*pMF",
  		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*pMF",
  		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 sizeof(m->tx_powerlevel), m->tx_powerlevel);
  exit:
  	kfree(m);
  }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
  	int ret;

drivers/net/wireless/at76c50x-usb.c static int at76_startup_device(struct at76_priv *priv) · line 1347

Quoted 10 lines
drivers/net/wireless/at76c50x-usb.c +2 -2
 
  	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*pMF) mode %s ch %d wep %s key %d "
  		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
  		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
  		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
  		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);

I have not yet tested this patch, but it generates warnings on a 64-bit system as follows:

CC [M] drivers/net/wireless/at76c50x-usb.o
drivers/net/wireless/at76c50x-usb.c: In function ‘at76_dump_mib_mdomain’:
drivers/net/wireless/at76c50x-usb.c:1133:2: warning: field width specifier ‘*’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat] drivers/net/wireless/at76c50x-usb.c:1137:2: warning: field width specifier ‘*’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]

Replacing "sizeof" by "(int)sizeof" removes the warning.

Larry

#7 lore raw

Re: [RFC][PATCH 1/2] lib: printf: append support of '%*p[Mm][FR]'

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Seems sensible, but one stack caveat below

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 12 lines
lib/vsprintf.c +3 -4
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-			 struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)
 {
-	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
-	char *p = mac_addr;
+	char hex_str[64*3];	/* support up to 64 bytes to print */

Might be too much stack though.

maintainer
#8 lore raw

Re: [RFC][PATCH 1/2] lib: printf: append support of '%*p[Mm][FR]'

Quoted 5 lines · On Fri, 29 Jun 2012 09:08:06 -0700 Joe Perches <[email protected]> wrote:

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

Quoted 3 lines
lib/vsprintf.c +0 -0
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
Quoted 11 lines

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 9 lines
lib/vsprintf.c +3 -4
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-			 struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)
 {
-	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
-	char *p = mac_addr;
+	char hex_str[64*3];	/* support up to 64 bytes to print */

Might be too much stack though.

Yes, it's a bit marginal, as this new capability might be used in debug or crash situations where we're deep into the stack. The average case could be improved by using alloca()-style allocation.

Documentation/printk-formats.txt would need to be updated please. Also the big comment over vsnprintf().

#9 lore raw

Re: [RFC][PATCH 1/2] lib: printf: append support of '%*p[Mm][FR]'

Quoted 20 lines · Andrew Morton
Quoted 5 lines · On Fri, 29 Jun 2012 09:08:06 -0700 Joe Perches <[email protected]> wrote:

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

Quoted 3 lines
lib/vsprintf.c +0 -0
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
Quoted 11 lines

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 9 lines
lib/vsprintf.c +3 -4
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-			 struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)
 {
-	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
-	char *p = mac_addr;
+	char hex_str[64*3];	/* support up to 64 bytes to print */

Might be too much stack though.

Quoted 3 lines

Yes, it's a bit marginal, as this new capability might be used in debug or crash situations where we're deep into the stack. The average case could be improved by using alloca()-style allocation.

Or maybe support larger sizes with a smaller
stack buffer and a while loop.

#10 lore raw

Re: [RFC][PATCH 1/2] lib: printf: append support of '%*p[Mm][FR]'

Quoted 21 lines · Joe Perches
Quoted 20 lines · Andrew Morton
Quoted 16 lines · On Fri, 29 Jun 2012 09:08:06 -0700 Joe Perches <[email protected]> wrote:

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 12 lines
lib/vsprintf.c +3 -4
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-                  struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+          const char *fmt)
 {
- char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
- char *p = mac_addr;
+ char hex_str[64*3];     /* support up to 64 bytes to print */

Might be too much stack though.

Quoted 6 lines
Quoted 3 lines

Yes, it's a bit marginal, as this new capability might be used in debug or crash situations where we're deep into the stack. The average case could be improved by using alloca()-style allocation.

Or maybe support larger sizes with a smaller
stack buffer and a while loop.

What do you think about mixed approach? Let's say we would use buffer on stack for 8 bytes or less, and allocated buffer in case of larger input. It allows to keep implementation simple.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [RFC][PATCH 1/2] lib: printf: append support of '%*p[Mm][FR]'

Quoted 26 lines · Andy Shevchenko
Quoted 25 lines · Joe Perches
Quoted 23 lines · Andrew Morton
Quoted 5 lines · On Fri, 29 Jun 2012 09:08:06 -0700 Joe Perches <[email protected]> wrote:

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

Quoted 3 lines
lib/vsprintf.c +0 -0
@@ -655,11 +655,12 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
Quoted 11 lines

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 9 lines
lib/vsprintf.c +3 -4
 static noinline_for_stack
-char *mac_address_string(char *buf, char *end, u8 *addr,
-                  struct printf_spec spec, const char *fmt)
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+          const char *fmt)
 {
- char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
- char *p = mac_addr;
+ char hex_str[64*3];     /* support up to 64 bytes to print */

Might be too much stack though.

Yes, it's a bit marginal, as this new capability might be used in debug or crash situations where we're deep into the stack. The average case could be improved by using alloca()-style allocation.

Quoted 7 lines
Quoted 2 lines

Or maybe support larger sizes with a smaller
stack buffer and a while loop.

What do you think about mixed approach? Let's say we would use buffer on stack for 8 bytes or less, and allocated buffer in case of larger input. It allows to keep implementation simple.

I think the while loop is simplest.
I'll code something up tomorrow unless
you get to it first.

author reviewer
#12 lore raw

RFC PATCH v2 1/3 lib: printf: update documentation to cover all of %p[Mm][FR]

---
 Documentation/printk-formats.txt |    1 +
 lib/vsprintf.c                   |    3 +++
 2 files changed, 4 insertions(+)
Documentation/printk-formats.txt +1 -0
index d8d168fa..90ff4d7 100644
@@ -59,6 +59,7 @@ MAC/FDDI addresses:
 	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
+	%pmR	050403020100
 
 	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
lib/vsprintf.c +3 -0
index a0b5f15..c65f5d4 100644
@@ -1287,7 +1287,10 @@ qualifier:
  * %pR output the address range in a struct resource with decoded flags
  * %pr output the address range in a struct resource with raw flags
  * %pM output a 6-byte MAC address with colons
+ * %pMR output a 6-byte MAC address with colons in reversed order
+ * %pMF output a 6-byte MAC address with dashes
  * %pm output a 6-byte MAC address without colons
+ * %pmR output a 6-byte MAC address without colons in reversed order
  * %pI4 print an IPv4 address without leading zeros
  * %pi4 print an IPv4 address with leading zeros
  * %pI6 print an IPv6 address with colons
Signature · 1 line
1.7.10
author reviewer
#13 lore raw

RFC PATCH v2 2/3 lib: printf: append support of '%*p[Mm][FR]'

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be look like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef
---
 Documentation/printk-formats.txt |    5 ++++
 lib/vsprintf.c                   |   49 ++++++++++++++++++++++++++------------
 2 files changed, 39 insertions(+), 15 deletions(-)
Documentation/printk-formats.txt +5 -0
index 90ff4d7..3ae3d32 100644
@@ -73,6 +73,11 @@ MAC/FDDI addresses:
 	specifier to use reversed byte order suitable for visual interpretation
 	of Bluetooth addresses which are in the little endian order.
 
+	Optional usage of all of the above is to specify variable length via
+	putting '*' into the specificator ('%*p[Mm][FR]'). In this case it will
+	print up to 64 bytes of the input as a hex string with certain
+	separator. For larger buffers consider to use print_hex_dump().
+
 IPv4 addresses:
 
 	%pI4	1.2.3.4
lib/vsprintf.c +34 -15

83 lines not on this page · raw message

Signature · 1 line
1.7.10
#14 lore raw

Re: [RFC][PATCHv2 2/3] lib: printf: append support of '%*p[Mm][FR]'

Quoted 11 lines · Andy Shevchenko

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be look like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef

Hi Andy.

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res,

Quoted 1 line
lib/vsprintf.c +0 -0
@@ -655,12 +655,13 @@ char *resource_string(char *buf, char *end, struct resource *res,

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 659

Quoted 2 lines
lib/vsprintf.c +2 -0
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)

[]

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr,

Quoted 1 line
lib/vsprintf.c +0 -0
@@ -678,18 +679,31 @@ char *mac_address_string(char *buf, char *end, u8 *addr,

[]

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr, · line 685

Quoted 1 line
lib/vsprintf.c +1 -0
+	while (i < len) {

Oh good, a while loop, thanks.

[]

lib/vsprintf.c int kptr_restrict __read_mostly; · line 966

Quoted 7 lines
lib/vsprintf.c +3 -0
@@ -947,6 +961,9 @@ int kptr_restrict __read_mostly;
  * - '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)
+ *       Optional usage is %*p[Mn][FR] with variable length to print. It
+ *       supports up to 64 bytes of the input. Consider to use print_hex_dump()
+ *       for the larger input.

It might be more sensible to use new, distinct "%*pH" and "%*ph" functions and not touch the mac address function at all. Will anyone ever really want to emit the buffer in reverse? I don't think so.

Perhaps when using a hex_string_buffer func the separator should be a space/no-space with %*pHh.

You could extend the max to 128 or larger now.

#15 lore raw

Re: [RFC][PATCHv2 2/3] lib: printf: append support of '%*p[Mm][FR]'

Quoted 13 lines · Joe Perches
Quoted 11 lines · Andy Shevchenko

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

      pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be look like this:
      [ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
      [ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
      [ 0.757602] buf[17:5] ac:16:d5:2c:ef
Quoted 5 lines

It might be more sensible to use new, distinct "%*pH" and "%*ph" functions and not touch the mac address function at all. Will anyone ever really want to emit the buffer in reverse? I don't think so.

Yeah, probably it's only the case for the Bluetooth addresses.

Quoted 2 lines

Perhaps when using a hex_string_buffer func the separator should be a space/no-space with %*pHh.

What I learned from today's linux-next is the most used separators are ' ' (space), '' (nothing), ':' and '-'. We have dozens of the cases for first three. The '-' support could not be implemented nevertheless.
So, might be %*pHh[CDS] C for 'colon', S for 'space', D for 'dash' looks better. 'Hh' for capital/small letters than?

Quoted 1 line

You could extend the max to 128 or larger now.

I don't think it is really needed. Most of the current cases usually print not more than ~30bytes (in average) per time. And I couldn't imagine good looking printing for long lines anyway.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [RFC][PATCHv2 2/3] lib: printf: append support of '%*p[Mm][FR]'

Quoted 21 lines · Andy Shevchenko
Quoted 13 lines · Joe Perches
Quoted 11 lines · Andy Shevchenko

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

      pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be look like this:
      [ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
      [ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
      [ 0.757602] buf[17:5] ac:16:d5:2c:ef
Quoted 5 lines

It might be more sensible to use new, distinct "%*pH" and "%*ph" functions and not touch the mac address function at all. Will anyone ever really want to emit the buffer in reverse? I don't think so.

Yeah, probably it's only the case for the Bluetooth addresses.

Quoted 7 lines
Quoted 2 lines

Perhaps when using a hex_string_buffer func the separator should be a space/no-space with %*pHh.

What I learned from today's linux-next is the most used separators are ' ' (space), '' (nothing), ':' and '-'. We have dozens of the cases for first three. The '-' support could not be implemented nevertheless.
So, might be %*pHh[CDS] C for 'colon', S for 'space', D for 'dash' looks better.

Maybe use a space default.

Quoted 1 line

'Hh' for capital/small letters than?

If you want, though I'd hope nobody uses upper case.

Quoted 2 lines
Quoted 1 line

You could extend the max to 128 or larger now.

I don't think it is really needed.

I hope it's not, but I just don't see the need to limit it.

Quoted 3 lines

Most of the current cases usually
print not more than ~30bytes (in average) per time. And I couldn't imagine good looking printing for long lines anyway.

Yup, they'd be ugly.
print_hex_dump() should be favored anyway.

cheers, Joe

author reviewer
#17 lore raw

PATCH v3 1/3 lib: printf: update documentation to cover all of %p[Mm][FR]

---
 Documentation/printk-formats.txt |    1 +
 lib/vsprintf.c                   |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
Documentation/printk-formats.txt +1 -0
index d8d168fa..90ff4d7 100644
@@ -59,6 +59,7 @@ MAC/FDDI addresses:
 	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
+	%pmR	050403020100
 
 	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
lib/vsprintf.c +4 -1
index a0b5f15..e500158 100644
@@ -946,7 +946,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - '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]R' For a 6-byte MAC address, Reverse order (Bluetooth)
  * - '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
@@ -1287,7 +1287,10 @@ qualifier:
  * %pR output the address range in a struct resource with decoded flags
  * %pr output the address range in a struct resource with raw flags
  * %pM output a 6-byte MAC address with colons
+ * %pMR output a 6-byte MAC address with colons in reversed order
+ * %pMF output a 6-byte MAC address with dashes
  * %pm output a 6-byte MAC address without colons
+ * %pmR output a 6-byte MAC address without colons in reversed order
  * %pI4 print an IPv4 address without leading zeros
  * %pi4 print an IPv4 address with leading zeros
  * %pI6 print an IPv6 address with colons
Signature · 1 line
1.7.10
author reviewer
#18 lore raw

PATCH v3 2/3 lib: printf: append support of '%*ph[CDN]'

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*phC\n", from, len, len, &buf[from]);
could be look like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef
---
 Documentation/printk-formats.txt |   10 ++++++
 lib/vsprintf.c                   |   62 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
Documentation/printk-formats.txt +10 -0
index 90ff4d7..8ffb274 100644
@@ -53,6 +53,16 @@ Struct Resources:
 	For printing struct resources. The 'R' and 'r' specifiers result in a
 	printed resource with ('R') or without ('r') a decoded flags member.
 
+Raw buffer as a hex string:
+	%*ph	00 01 02  ...  3f
+	%*phC	00:01:02: ... :3f
+	%*phD	00-01-02- ... -3f
+	%*phN	000102 ... 3f
+
+	For printing a small buffers (up to 64 bytes long) as a hex string with
+	certain separator. For the larger buffers consider to use
+	print_hex_dump().
+
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
lib/vsprintf.c +62 -0

86 lines not on this page · raw message

Signature · 1 line
1.7.10
#19 lore raw

Re: [PATCHv3 2/3] lib: printf: append support of '%*ph[CDN]'

Quoted 2 lines · Andy Shevchenko

This patch adds a support of the variable width buffer to print it as a hex string with a delimiter.

Hi again Andy.

lib/vsprintf.c

Quoted 1 line
lib/vsprintf.c +0 -0

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 661

Quoted 8 lines
lib/vsprintf.c +4 -0
@@ -655,6 +655,57 @@ char *resource_string(char *buf, char *end, struct resource *res,
 }
 
 static noinline_for_stack
+char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
+		 const char *fmt)
+{
+	char hex_str[8*3+1];	/* support up to 8 bytes to print */

I think you don't need hex_str at all.

[]

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 684

Quoted 3 lines
lib/vsprintf.c +3 -0
+	if (spec.field_width <= 0)
+		/* nothing to print */
+		return buf;

It may be better to default to a 1 and add

	if (addr == ZERO_OR_NULL_PTR)

to avoid dereferencing a NULL or a pointer
to a zero length object.

Quoted 8 lines
lib/vsprintf.c +8 -0
+
+	len = min_t(int, spec.field_width, 64);
+
+	while (i < len) {
+		p = hex_str;
+		for (j = 0; j < 8 && i < len; j++, i++) {
+			p = hex_byte_pack(p, addr[i]);
+

lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 702

Quoted 10 lines
lib/vsprintf.c +10 -0
+			if (separator && i != len - 1)
+				*p++ = separator;
+		}
+		*p = '\0';
+
+		for (p = hex_str; *p != '\0'; p++) {
+			if (buf < end)
+				*buf = *p;
+			++buf;
+		}

why not just directly write to *buf as long as buf < end?

cheers, Joe

#20 lore raw

Re: [PATCHv3 2/3] lib: printf: append support of '%*ph[CDN]'

Quoted 8 lines · Joe Perches
Quoted 6 lines · Andy Shevchenko

This patch adds a support of the variable width buffer to print it as a hex string with a delimiter.

+     if (spec.field_width <= 0)
+             /* nothing to print */
+             return buf;

Quoted 6 lines

It may be better to default to a 1 and add

        if (addr == ZERO_OR_NULL_PTR)

to avoid dereferencing a NULL or a pointer
to a zero length object.

Good point.

Quoted 7 lines
Quoted 5 lines

+             for (p = hex_str; *p != '\0'; p++) {
+                     if (buf < end)
+                             *buf = *p;
+                     ++buf;
+             }

why not just directly write to *buf as long as buf < end?

buf < end - 1, otherwise correct.
And yes, it eliminates hex_str array as well.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#21 lore raw

[PATCHv3.5] lib: printf: append support of '%*ph[CDN]'

In reply to Joe Perches

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*phC\n", from, len, len, &buf[from]);
could be look like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef
---
 Documentation/printk-formats.txt |   10 +++++++
 lib/vsprintf.c                   |   58 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
Documentation/printk-formats.txt +10 -0
index 90ff4d7..8ffb274 100644
@@ -53,6 +53,16 @@ Struct Resources:
 	For printing struct resources. The 'R' and 'r' specifiers result in a
 	printed resource with ('R') or without ('r') a decoded flags member.
 
+Raw buffer as a hex string:
+	%*ph	00 01 02  ...  3f
+	%*phC	00:01:02: ... :3f
+	%*phD	00-01-02- ... -3f
+	%*phN	000102 ... 3f
+
+	For printing a small buffers (up to 64 bytes long) as a hex string with
+	certain separator. For the larger buffers consider to use
+	print_hex_dump().
+
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
lib/vsprintf.c +58 -0

82 lines not on this page · raw message

Signature · 1 line
1.7.10
author reviewer
#22 lore raw

[PATCHv3.6] lib: printf: append support of '%*ph[CDN]'

In reply to Joe Perches

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Sample output of

	pr_info("buf[%d:%d] %*phC\n", from, len, len, &buf[from]);
could be look like this:
	[ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
	[ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
	[ 0.757602] buf[17:5] ac:16:d5:2c:ef
---
 Documentation/printk-formats.txt |   10 +++++++
 lib/vsprintf.c                   |   55 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
Documentation/printk-formats.txt +10 -0
index 90ff4d7..8ffb274 100644
@@ -53,6 +53,16 @@ Struct Resources:
 	For printing struct resources. The 'R' and 'r' specifiers result in a
 	printed resource with ('R') or without ('r') a decoded flags member.
 
+Raw buffer as a hex string:
+	%*ph	00 01 02  ...  3f
+	%*phC	00:01:02: ... :3f
+	%*phD	00-01-02- ... -3f
+	%*phN	000102 ... 3f
+
+	For printing a small buffers (up to 64 bytes long) as a hex string with
+	certain separator. For the larger buffers consider to use
+	print_hex_dump().
+
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
lib/vsprintf.c +55 -0

79 lines not on this page · raw message

Signature · 1 line
1.7.10
author reviewer
#23 lore raw

PATCH v3 3/3 wireless: at76c50x: eliminate hex2str()

In reply to Andy Shevchenko

The hex2str() is substituted by '%*phD' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index efc162e..e5bd2ad 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*phD",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*phD current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*phD desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 (int)sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 (int)sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*phD) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 1 line
1.7.10
author reviewer
#24 lore raw

PATCH RESEND 1/1 wireless: at76c50x: eliminate hex2str()

The hex2str() is substituted by '%*phD' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index e361afe..99b9ddf 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*phD",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*phD current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*phD desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 (int)sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 (int)sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*phD) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 1 line
1.7.10.4
#25 lore raw

Re: [resend][PATCH] wireless: at76c50x: eliminate hex2str()

Could you point me at the commit that adds the 'phD' specification?

Quoted 136 lines · Andy Shevchenko

The hex2str() is substituted by '%*phD' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index e361afe..99b9ddf 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*phD",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*phD current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*phD desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 (int)sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 (int)sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*phD) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
author reviewer
#26 lore raw

Re: [resend][PATCH] wireless: at76c50x: eliminate hex2str()

Quoted 1 line · John W. Linville

Could you point me at the commit that adds the 'phD' specification?

There it is:
http://www.spinics.net/lists/linux-wireless/msg93694.html

commit 31550a16a5d2af859e8a11839e8c6c6c9c92dfa7

Quoted 138 lines · Andy Shevchenko
Quoted 136 lines

The hex2str() is substituted by '%*phD' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index e361afe..99b9ddf 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*phD",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*phD current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*phD desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 (int)sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*phD",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 (int)sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*phD) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Acked-by Andrei Emeltchenko on v3 1/3
#27 lore raw

Re: [PATCHv3 1/3] lib: printf: update documentation to cover all of %p[Mm][FR]

In reply to Andy Shevchenko
Quoted 1 line · Andy Shevchenko
Quoted 48 lines
---
 Documentation/printk-formats.txt |    1 +
 lib/vsprintf.c                   |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
Documentation/printk-formats.txt +1 -0
index d8d168fa..90ff4d7 100644
@@ -59,6 +59,7 @@ MAC/FDDI addresses:
 	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
+	%pmR	050403020100
 
 	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
lib/vsprintf.c +4 -1
index a0b5f15..e500158 100644
@@ -946,7 +946,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - '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]R' For a 6-byte MAC address, Reverse order (Bluetooth)
  * - '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
@@ -1287,7 +1287,10 @@ qualifier:
  * %pR output the address range in a struct resource with decoded flags
  * %pr output the address range in a struct resource with raw flags
  * %pM output a 6-byte MAC address with colons
+ * %pMR output a 6-byte MAC address with colons in reversed order
+ * %pMF output a 6-byte MAC address with dashes
  * %pm output a 6-byte MAC address without colons
+ * %pmR output a 6-byte MAC address without colons in reversed order
  * %pI4 print an IPv4 address without leading zeros
  * %pi4 print an IPv4 address with leading zeros
  * %pI6 print an IPv6 address with colons
Signature · 6 lines
1.7.10

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#28 lore raw

Re: [RFC][PATCHv2 2/3] lib: printf: append support of '%*p[Mm][FR]'

In reply to Joe Perches

Hi,

Quoted 8 lines · Joe Perches
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Joe Perches
Quoted 5 lines · Andy Shevchenko

There are many places in the kernel where the drivers print small buffers as a hex string. This patch adds a support of the variable width buffer to print it as a hex string with a delimiter. The idea came from Pavel Roskin here:
http://www.digipedia.pl/usenet/thread/18835/17449/

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Sample output of

      pr_info("buf[%d:%d] %*pM\n", from, len, len, &buf[from]);
could be look like this:
      [ 0.726130] buf[51:8] e8:16:b6:ef:e3:74:45:6e
      [ 0.750736] buf[59:15] 31:81:b8:3f:35:49:06:ae:df:32:06:05:4a:af:55
      [ 0.757602] buf[17:5] ac:16:d5:2c:ef

The idea is really good and can make redundant lots of print_hex functions.

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

It might be more sensible to use new, distinct "%*pH" and "%*ph" functions and not touch the mac address function at all. Will anyone ever really want to emit the buffer in reverse? I don't think so.

Yeah, probably it's only the case for the Bluetooth addresses.

Quoted 2 lines

Perhaps when using a hex_string_buffer func the separator should be a space/no-space with %*pHh.

Quoted 7 lines
Quoted 5 lines

What I learned from today's linux-next is the most used separators are ' ' (space), '' (nothing), ':' and '-'. We have dozens of the cases for first three. The '-' support could not be implemented nevertheless.
So, might be %*pHh[CDS] C for 'colon', S for 'space', D for 'dash' looks better.

Maybe use a space default.

I do not think we need other specifier then space at all.

Quoted 13 lines
Quoted 2 lines

'Hh' for capital/small letters than?

If you want, though I'd hope nobody uses upper case.

Quoted 2 lines
Quoted 1 line

You could extend the max to 128 or larger now.

I don't think it is really needed.

I hope it's not, but I just don't see the need to limit it.

Quoted 3 lines

Most of the current cases usually
print not more than ~30bytes (in average) per time. And I couldn't imagine good looking printing for long lines anyway.

Maybe insert '\n' after 16 numbers?

Quoted 3 lines

Yup, they'd be ugly.
print_hex_dump() should be favored anyway.

For print_hex_dump we would need to invent unreadable constructions with defines like you mentioned in other thread:

#ifdef SOME_BLUETOOTH_DEBUG_FLAG

#define bt_hex_dump_dbg(...)    \
        print_hex_dump(...)
#else
#define bt_hex_dump_dbg(...)    \
        do { } while (0)

#endif

Best regards
Andrei Emeltchenko

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki
Business Identity Code: 0357606 - 4
Domiciled in Helsinki

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

author reviewer
#29 lore raw

RFC PATCH v2 3/3 wireless: at76c50x: eliminate hex2str()

In reply to Andy Shevchenko

The hex2str() is substituted by '%*pMF' specificator.

---
 drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/wireless/at76c50x-usb.c +12 -42
index efc162e..f82f76b 100644
@@ -498,36 +498,6 @@ exit:
 	return ret;
 }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
 /* LED trigger */
 static int tx_activity;
 static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
 	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
 	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*pMF",
 			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
 exit:
 	kfree(m);
 }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
 		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
 		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*pMF current_bss_type %d "
 		 "pm_mode %d ibss_change %d res %d "
 		 "multi_domain_capability_implemented %d "
 		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
 		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
 		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
 		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
 		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
 		 m->res, m->multi_domain_capability_implemented,
 		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
 		 "scan_type %d scan_channel %d probe_delay %u "
 		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*pMF desired_bssid %pM desired_bsstype %d",
 		 wiphy_name(priv->hw->wiphy),
 		 le32_to_cpu(m->max_tx_msdu_lifetime),
 		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
 		 le16_to_cpu(m->min_channel_time),
 		 le16_to_cpu(m->max_channel_time),
 		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
 		 m->desired_bssid, m->desired_bsstype);
 exit:
 	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
 		goto exit;
 	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*pMF",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*pMF",
 		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 sizeof(m->tx_powerlevel), m->tx_powerlevel);
 exit:
 	kfree(m);
 }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
 	int ret;
 
 	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*pMF) mode %s ch %d wep %s key %d "
 		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
 		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
 		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
 		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
Signature · 1 line
1.7.10
Tested-by on v2 3/3
#30 lore raw

Re: [RFC][PATCHv2 3/3] wireless: at76c50x: eliminate hex2str()

Quoted 6 lines · Andy Shevchenko

The hex2str() is substituted by '%*pMF' specificator.

---
  drivers/net/wireless/at76c50x-usb.c |   54 ++++++++---------------------------
  1 file changed, 12 insertions(+), 42 deletions(-)
Quoted 121 lines
drivers/net/wireless/at76c50x-usb.c +12 -42
index efc162e..f82f76b 100644
@@ -498,36 +498,6 @@ exit:
  	return ret;
  }
 
-#define HEX2STR_BUFFERS 4
-#define HEX2STR_MAX_LEN 64
-
-/* Convert binary data into hex string */
-static char *hex2str(void *buf, size_t len)
-{
-	static atomic_t a = ATOMIC_INIT(0);
-	static char bufs[HEX2STR_BUFFERS][3 * HEX2STR_MAX_LEN + 1];
-	char *ret = bufs[atomic_inc_return(&a) & (HEX2STR_BUFFERS - 1)];
-	char *obuf = ret;
-	u8 *ibuf = buf;
-
-	if (len > HEX2STR_MAX_LEN)
-		len = HEX2STR_MAX_LEN;
-
-	if (len == 0)
-		goto exit;
-
-	while (len--) {
-		obuf = hex_byte_pack(obuf, *ibuf++);
-		*obuf++ = '-';
-	}
-	obuf--;
-
-exit:
-	*obuf = '\0';
-
-	return ret;
-}
-
  /* LED trigger */
  static int tx_activity;
  static void at76_ledtrig_tx_timerfunc(unsigned long data);
@@ -1004,9 +974,9 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv)
  	    WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
  	for (i = 0; i < WEP_KEYS; i++)
-		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s",
+		at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*pMF",
  			 wiphy_name(priv->hw->wiphy), i,
-			 hex2str(m->wep_default_keyvalue[i], key_len));
+			 key_len, m->wep_default_keyvalue[i]);
  exit:
  	kfree(m);
  }
@@ -1031,7 +1001,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
  	at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
  		 "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
  		 "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
-		 "current_bssid %pM current_essid %s current_bss_type %d "
+		 "current_bssid %pM current_essid %*pMF current_bss_type %d "
  		 "pm_mode %d ibss_change %d res %d "
  		 "multi_domain_capability_implemented %d "
  		 "international_roaming %d country_string %.3s",
@@ -1041,7 +1011,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
  		 le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
  		 m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
  		 m->CFP_period, m->current_bssid,
-		 hex2str(m->current_essid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->current_essid,
  		 m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
  		 m->res, m->multi_domain_capability_implemented,
  		 m->multi_domain_capability_enabled, m->country_string);
@@ -1069,7 +1039,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
  		 "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
  		 "scan_type %d scan_channel %d probe_delay %u "
  		 "min_channel_time %d max_channel_time %d listen_int %d "
-		 "desired_ssid %s desired_bssid %pM desired_bsstype %d",
+		 "desired_ssid %*pMF desired_bssid %pM desired_bsstype %d",
  		 wiphy_name(priv->hw->wiphy),
  		 le32_to_cpu(m->max_tx_msdu_lifetime),
  		 le32_to_cpu(m->max_rx_lifetime),
@@ -1080,7 +1050,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv)
  		 le16_to_cpu(m->min_channel_time),
  		 le16_to_cpu(m->max_channel_time),
  		 le16_to_cpu(m->listen_interval),
-		 hex2str(m->desired_ssid, IW_ESSID_MAX_SIZE),
+		 IW_ESSID_MAX_SIZE, m->desired_ssid,
  		 m->desired_bssid, m->desired_bsstype);
  exit:
  	kfree(m);
@@ -1160,13 +1130,13 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv)
  		goto exit;
  	}
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*pMF",
  		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->channel_list, sizeof(m->channel_list)));
+		 sizeof(m->channel_list), m->channel_list);
 
-	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s",
+	at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*pMF",
  		 wiphy_name(priv->hw->wiphy),
-		 hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel)));
+		 sizeof(m->tx_powerlevel), m->tx_powerlevel);
  exit:
  	kfree(m);
  }
@@ -1369,9 +1339,9 @@ static int at76_startup_device(struct at76_priv *priv)
  	int ret;
 
  	at76_dbg(DBG_PARAMS,
-		 "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d "
+		 "%s param: ssid %.*s (%*pMF) mode %s ch %d wep %s key %d "
  		 "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
-		 priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE),
+		 priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
  		 priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
  		 priv->channel, priv->wep_enabled ? "enabled" : "disabled",
  		 priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
#31 lore raw

Re: [RFC][PATCHv2 3/3] wireless: at76c50x: eliminate hex2str()

Quoted 4 lines · Larry Finger
Quoted 3 lines · Andy Shevchenko

The hex2str() is substituted by '%*pMF' specificator.

Quoted 8 lines
Quoted 5 lines
---
  drivers/net/wireless/at76c50x-usb.c |   54
++++++++---------------------------
  1 file changed, 12 insertions(+), 42 deletions(-)

Thanks for testing. Today I found in my mailbox (not gmail) your previous message about compilation warnings. Are they still present? (I guess so) Probably I need to update the patch (anyway it probably has to be updated because we discussed with Joe about different letter for the hex strings).

Signature · 2 lines
With Best Regards,
Andy Shevchenko