Skip to content

Commit 3050c18

Browse files
committed
drm/print: add drm_print_hex_dump()
Add a helper to print a hex dump to a struct drm_printer. There's no fancy formatting stuff, just 16 space-separated bytes per line, with an optional prefix. Reviewed-by: Andi Shyti <[email protected]> Acked-by: Thomas Zimmermann <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/f650fe1ed3e3bb74760426fa7461c3b028d661fb.1733392101.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <[email protected]>
1 parent b031ef5 commit 3050c18

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/gpu/drm/drm_print.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,26 @@ void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset)
390390
}
391391
}
392392
EXPORT_SYMBOL(drm_print_regset32);
393+
394+
/**
395+
* drm_print_hex_dump - print a hex dump to a &drm_printer stream
396+
* @p: The &drm_printer
397+
* @prefix: Prefix for each line, may be NULL for no prefix
398+
* @buf: Buffer to dump
399+
* @len: Length of buffer
400+
*
401+
* Print hex dump to &drm_printer, with 16 space-separated hex bytes per line,
402+
* optionally with a prefix on each line. No separator is added after prefix.
403+
*/
404+
void drm_print_hex_dump(struct drm_printer *p, const char *prefix,
405+
const u8 *buf, size_t len)
406+
{
407+
int i;
408+
409+
for (i = 0; i < len; i += 16) {
410+
int bytes_per_line = min(16, len - i);
411+
412+
drm_printf(p, "%s%*ph\n", prefix ?: "", bytes_per_line, buf + i);
413+
}
414+
}
415+
EXPORT_SYMBOL(drm_print_hex_dump);

include/drm/drm_print.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ void drm_puts(struct drm_printer *p, const char *str);
199199
void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
200200
void drm_print_bits(struct drm_printer *p, unsigned long value,
201201
const char * const bits[], unsigned int nbits);
202+
void drm_print_hex_dump(struct drm_printer *p, const char *prefix,
203+
const u8 *buf, size_t len);
202204

203205
__printf(2, 0)
204206
/**

0 commit comments

Comments
 (0)