Skip to contentSkip to conversation

iwlwifi: convert hex_dump_to_buffer() to %*ph

PATCH Applied Andy Shevchenko 5 participants 6 messages Jul 16, 2015 – Aug 4, 2015 1 message not in the archive

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

PATCH 1/2 iwlwifi: convert hex_dump_to_buffer() to %*ph

There is no need to use hex_dump_to_buffer() in the cases like this:

	hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);	/* len <= 16 */
	sprintf("%s\n", outbuf);

since it maybe easily converted to simple:

	sprintf("%*ph\n", len, buf);

Note: it seems in one case the output is groupped by 2 bytes and looks like a typo. Thus, patch changes that to plain byte stream.

---
 drivers/net/wireless/iwlwifi/dvm/debugfs.c | 8 ++------
 drivers/net/wireless/iwlwifi/mvm/debugfs.c | 7 +------
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/net/wireless/iwlwifi/dvm/debugfs.c +2 -6
index 0ffb6ff..b15e44f 100644
@@ -310,12 +310,8 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
 	pos += scnprintf(buf + pos, buf_size - pos,
 			 "NVM version: 0x%x\n", nvm_ver);
 	for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
-		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
-		hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
-				   buf_size - pos, 0);
-		pos += strlen(buf + pos);
-		if (buf_size - pos > 0)
-			buf[pos++] = '\n';
+		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
+				 ofs, ptr + ofs);
 	}
 
 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
drivers/net/wireless/iwlwifi/mvm/debugfs.c +1 -6
index ffb4b5c..98abd31 100644
@@ -1200,12 +1200,7 @@ static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
 	if (ptr) {
 		for (ofs = 0; ofs < len; ofs += 16) {
 			pos += scnprintf(buf + pos, bufsz - pos,
-					 "0x%.4x ", ofs);
-			hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
-					   bufsz - pos, false);
-			pos += strlen(buf + pos);
-			if (bufsz - pos > 0)
-				buf[pos++] = '\n';
+					 "0x%.4x %16ph\n", ofs, ptr + ofs);
 		}
 	} else {
 		pos += scnprintf(buf + pos, bufsz - pos,
Signature · 6 lines
2.1.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
#1 lore raw

PATCH 2/2 iwlegacy: convert hex_dump_to_buffer() to %*ph

There is no need to use hex_dump_to_buffer() in the cases like this:

	hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);	/* len <= 16 */
	sprintf("%s\n", outbuf);

since it maybe easily converted to simple:

	sprintf("%*ph\n", len, buf);

Note: it seems in the case the output is groupped by 2 bytes and looks like a typo. Thus, patch changes that to plain byte stream.

---
 drivers/net/wireless/iwlegacy/3945-mac.c | 2 +-
 drivers/net/wireless/iwlegacy/debug.c    | 8 ++------
 2 files changed, 3 insertions(+), 7 deletions(-)
drivers/net/wireless/iwlegacy/3945-mac.c +1 -1
index 7f4cb69..af1b3e6 100644
@@ -3259,7 +3259,7 @@ il3945_show_measurement(struct device *d, struct device_attribute *attr,
 
 	while (size && PAGE_SIZE - len) {
 		hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
-				   PAGE_SIZE - len, 1);
+				   PAGE_SIZE - len, true);
 		len = strlen(buf);
 		if (PAGE_SIZE - len)
 			buf[len++] = '\n';
drivers/net/wireless/iwlegacy/debug.c +2 -6
index 3440101..908b9f4 100644
@@ -515,12 +515,8 @@ il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
 	    scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
 		      eeprom_ver);
 	for (ofs = 0; ofs < eeprom_len; ofs += 16) {
-		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
-		hex_dump_to_buffer(ptr + ofs, 16, 16, 2, buf + pos,
-				   buf_size - pos, 0);
-		pos += strlen(buf + pos);
-		if (buf_size - pos > 0)
-			buf[pos++] = '\n';
+		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
+				 ofs, ptr + ofs);
 	}
 
 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Signature · 1 line
2.1.4
Applied
#2 lore raw

Re: [2/2] iwlegacy: convert hex_dump_to_buffer() to %*ph

Quoted 6 lines

There is no need to use hex_dump_to_buffer() in the cases like this:

	hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);	/* len <= 16 */
	sprintf("%s\n", outbuf);
Quoted 8 lines

since it maybe easily converted to simple:

	sprintf("%*ph\n", len, buf);

Note: it seems in the case the output is groupped by 2 bytes and looks like a typo. Thus, patch changes that to plain byte stream.

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#3 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

There is no need to use hex_dump_to_buffer() in the cases like this:

	hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);	> /* len <= 16 
*/
	sprintf("%s\n", outbuf);
Quoted 7 lines

since it maybe easily converted to simple:

	sprintf("%*ph\n", len, buf);

Note: it seems in one case the output is groupped by 2 bytes and looks like a
typo. Thus, patch changes that to plain byte stream.

Any comments on this, anyone?

The idea is to minimize usage of hexdump_to_buffer(), i.e. not using it when it's an obvious overkill.

Quoted 53 lines
---
 drivers/net/wireless/iwlwifi/dvm/debugfs.c | 8 ++------
 drivers/net/wireless/iwlwifi/mvm/debugfs.c | 7 +------
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/net/wireless/iwlwifi/dvm/debugfs.c +2 -6
index 0ffb6ff..b15e44f 100644
@@ -310,12 +310,8 @@ static ssize_t iwl_dbgfs_nvm_read(struct file 
 *file,
 	pos += scnprintf(buf + pos, buf_size - pos,
 			 "NVM version: 0x%x\n", nvm_ver);
 	for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
-		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x 
 ", ofs);
-		hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
-				   buf_size - pos, 0);
-		pos += strlen(buf + pos);
-		if (buf_size - pos > 0)
-			buf[pos++] = '\n';
+		pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x 
 %16ph\n",
+				 ofs, ptr + ofs);
drivers/net/wireless/iwlwifi/dvm/debugfs.c +0 -0
 	}
 
 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, 

pos);

drivers/net/wireless/iwlwifi/mvm/debugfs.c +3 -6
index ffb4b5c..98abd31 100644
@@ -1200,12 +1200,7 @@ static ssize_t iwl_dbgfs_d3_sram_read(struct 
 file *file, char __user *user_buf,
 	if (ptr) {
 		for (ofs = 0; ofs < len; ofs += 16) {
 			pos += scnprintf(buf + pos, bufsz - pos,
-					 "0x%.4x ", ofs);
-			hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf 
+ pos,
-					   bufsz - pos, false);
-			pos += strlen(buf + pos);
-			if (bufsz - pos > 0)
-				buf[pos++] = '\n';
+					 "0x%.4x %16ph\n", ofs, ptr 
+ ofs);
 		}
 	} else {
 		pos += scnprintf(buf + pos, bufsz - pos,
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

A message that is not in the archive (sent off-list or not yet received): 1438685233.29746.156.camel-VuQAYsv1563Yd54FQh9/[email protected]

#5 lore raw
Quoted 16 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

There is no need to use hex_dump_to_buffer() in the cases like this:

      hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);      > /* len <= 16
*/
      sprintf("%s\n", outbuf);
Quoted 7 lines

since it maybe easily converted to simple:

      sprintf("%*ph\n", len, buf);

Note: it seems in one case the output is groupped by 2 bytes and looks like a
typo. Thus, patch changes that to plain byte stream.

Quoted 5 lines

Any comments on this, anyone?

The idea is to minimize usage of hexdump_to_buffer(), i.e. not using it when it's an obvious overkill.

Sorry for the delay, since the buffer is small (less than 16 bytes, it should be fine).
--
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

#6 lore raw
Quoted 18 lines · Emmanuel Grumbach
Quoted 16 lines · Andy Shevchenko
Quoted 13 lines · Andy Shevchenko

There is no need to use hex_dump_to_buffer() in the cases like this:

      hexdump_to_buffer(buf, len, 16, 1, outbuf, outlen, false);      > /* len <= 16
*/
      sprintf("%s\n", outbuf);

since it maybe easily converted to simple:

      sprintf("%*ph\n", len, buf);

Note: it seems in one case the output is groupped by 2 bytes and looks like a
typo. Thus, patch changes that to plain byte stream.

Quoted 8 lines
Quoted 5 lines

Any comments on this, anyone?

The idea is to minimize usage of hexdump_to_buffer(), i.e. not using it when it's an obvious overkill.

Sorry for the delay, since the buffer is small (less than 16 bytes, it should be fine).

I applied it on our internal tree. Thank you.