Skip to content

Commit dc83f26

Browse files
Nick ChildNipaLocal
authored andcommitted
hexdump: Implement macro for converting large buffers
Define for_each_line_in_hex_dump which loops over a buffer and calls hex_dump_to_buffer for each segment in the buffer. This allows the caller to decide what to do with the resulting string and is not limited by a specific printing format like print_hex_dump. Signed-off-by: Nick Child <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 9e0b4e5 commit dc83f26

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/linux/printk.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,27 @@ enum {
755755
extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
756756
int groupsize, char *linebuf, size_t linebuflen,
757757
bool ascii);
758+
/**
759+
* for_each_line_in_hex_dump - iterate over buffer, converting into hex ASCII
760+
* @i: offset in @buff
761+
* @rowsize: number of bytes to print per line; must be 16 or 32
762+
* @linebuf: where to put the converted data
763+
* @linebuflen: total size of @linebuf, including space for terminating NUL
764+
* IOW >= (@rowsize * 2) + ((@rowsize - 1 / @groupsize)) + 1
765+
* @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
766+
* @buf: data blob to dump
767+
* @len: number of bytes in the @buf
768+
*/
769+
#define for_each_line_in_hex_dump(i, rowsize, linebuf, linebuflen, groupsize, \
770+
buf, len) \
771+
for ((i) = 0; \
772+
(i) < (len) && \
773+
hex_dump_to_buffer((unsigned char *)(buf) + (i), \
774+
min((len) - (i), rowsize), \
775+
(rowsize), (groupsize), (linebuf), \
776+
(linebuflen), false); \
777+
(i) += (rowsize) == 16 || (rowsize) == 32 ? (rowsize) : 16 \
778+
)
758779
#ifdef CONFIG_PRINTK
759780
extern void print_hex_dump(const char *level, const char *prefix_str,
760781
int prefix_type, int rowsize, int groupsize,

0 commit comments

Comments
 (0)