Skip to contentSkip to conversation

staging: gpib: replace dump function by print_hex_dump

PATCH New Kees Bakker 1 participant 1 message Oct 17, 2024 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: gpib: replace dump function by print_hex_dump

It is better to use a standard (proven in use) in-kernel function that does the same. This also solves two buffer overflow problems.

---
 .../staging/gpib/agilent_82357a/agilent_82357a.c   | 14 +-------------
 drivers/staging/gpib/ni_usb/ni_usb_gpib.c          | 14 +-------------
 2 files changed, 2 insertions(+), 26 deletions(-)
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +1 -13
index bbc7e8866872..bb494eea0920 100644
@@ -207,20 +207,8 @@ static int agilent_82357a_receive_control_msg(struct agilent_82357a_priv *a_priv
 
 static void agilent_82357a_dump_raw_block(const u8 *raw_data, int length)
 {
-#define RAW_BUF_SIZE 256
-	int i, pos = 0;
-	char print_buf[RAW_BUF_SIZE];
-
 	pr_info("hex block dump\n");
-	for (i = 0; i < length; ++i) {
-		if (i && (i % 8 == 0)) {
-			pr_info("%s\n", print_buf);
-			pos = 0;
-		}
-		pos += snprintf(&print_buf[pos], RAW_BUF_SIZE, " %02x", raw_data[i]);
-	}
-	if (pos)
-		pr_info("%s\n", print_buf);
+	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 8, 1, raw_data, length, true);
 }
 
 static int agilent_82357a_write_registers(struct agilent_82357a_priv *a_priv,
drivers/staging/gpib/ni_usb/ni_usb_gpib.c +1 -13
index 1da263676f2a..d5b6d0932cd9 100644
@@ -354,20 +354,8 @@ static int ni_usb_parse_status_block(const u8 *buffer, struct ni_usb_status_bloc
 
 static void ni_usb_dump_raw_block(const u8 *raw_data, int length)
 {
-#define RAW_BUF_SIZE 256
-	int i, pos = 0;
-	char print_buf[RAW_BUF_SIZE];
-
 	pr_info("hex block dump\n");
-	for (i = 0; i < length; ++i) {
-		if (i && (i % 8 == 0)) {
-			pr_info("%s\n", print_buf);
-			pos = 0;
-		}
-		pos += snprintf(&print_buf[pos], RAW_BUF_SIZE, " %02x", raw_data[i]);
-	}
-	if (pos)
-		pr_info("%s\n", print_buf);
+	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 8, 1, raw_data, length, true);
 }
 
 static int ni_usb_parse_register_read_block(const u8 *raw_data, unsigned int *results,
Signature · 1 line
2.47.0