[PATCH 2/3] hexdump: Use for_each macro in print_hex_dump

From: Nick Child
Date: Mon Jan 13 2025 - 17:17:58 EST


The looping logic in print_hex_dump can be handled by the macro
for_each_line_in_hex_dump.

Signed-off-by: Nick Child <nnac123@xxxxxxxxxxxxx>
---
lib/hexdump.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/lib/hexdump.c b/lib/hexdump.c
index c3db7c3a7643..181b82dfe40d 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -263,19 +263,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
const void *buf, size_t len, bool ascii)
{
const u8 *ptr = buf;
- int i, linelen, remaining = len;
+ int i;
unsigned char linebuf[32 * 3 + 2 + 32 + 1];

if (rowsize != 16 && rowsize != 32)
rowsize = 16;

- for (i = 0; i < len; i += rowsize) {
- linelen = min(remaining, rowsize);
- remaining -= rowsize;
-
- hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
- linebuf, sizeof(linebuf), ascii);
-
+ for_each_line_in_hex_dump(i, rowsize, linebuf, sizeof(linebuf),
+ groupsize, buf, len) {
switch (prefix_type) {
case DUMP_PREFIX_ADDRESS:
printk("%s%s%p: %s\n",
--
2.47.1