drm_coredump_printer(9)
β¨ drm_coredump_printer β¨
okay so this is a page from the Kernel API Manual, and today's main character is drm_coredump_printer β the little helper that builds you a &drm_printer capable of writing out to a buffer straight from the read function for devcoredump. bestie, it's giving "glue code that slays" π
π NAME π
drm_coredump_printer β construct a &drm_printer that can output to a buffer from the read function for devcoredump
π SYNOPSIS π
struct drm_printer drm_coredump_printer (struct drm_print_iterator *iter
);
π¦ ARGUMENTS π¦
iterβ a pointer to astruct drm_print_iteratorfor the read instance. that's the one, that's the whole arg π«Ά
πΈ DESCRIPTION πΈ
so this wrapper lowkey extends drm_printf so it plays nice with a dev_coredumpm callback function. the drm_print_iterator struct you pass in is carrying the buffer pointer, the size and the offset, all exactly as they came in from devcoredump. no cap, that's it π
for example:
void coredump_read(char *buffer, loff_t offset, size_t count,
void *data, size_t datalen)
{
struct drm_print_iterator iter;
struct drm_printer p;
iter.data = buffer;
iter.start = offset;
iter.remain = count;
p = drm_coredump_printer(iter);
drm_printf(p, "foo=d0, foo);
}
void makecoredump(...)
{
...
dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL,
coredump_read, ...)
}
okay so real talk about that example: it has a time complexity of O(N^2), where N is the size of the devcoredump. that's totally fine for small devcoredumps, but ngl it scales poorly for the big ones π
another use case for drm_coredump_printer is capturing the devcoredump into a saved buffer before the dev_coredump callback. this is a two-pass situation, bestie: one pass to figure out the size of the devcoredump, and another pass to print it into a buffer. then, in dev_coredump, you copy from the saved buffer into the devcoredump read buffer. iconic, honestly β¨
for example:
char *devcoredump_saved_buffer;
ssize_t __coredump_print(char *buffer, ssize_t count, ...)
{
struct drm_print_iterator iter;
struct drm_printer p;
iter.data = buffer;
iter.start = 0;
iter.remain = count;
p = drm_coredump_printer(iter);
drm_printf(p, "foo=d0, foo);
...
return count - iter.remain;
}
void coredump_print(...)
{
ssize_t count;
count = __coredump_print(NULL, INT_MAX, ...);
devcoredump_saved_buffer = kvmalloc(count, GFP_KERNEL);
__coredump_print(devcoredump_saved_buffer, count, ...);
}
void coredump_read(char *buffer, loff_t offset, size_t count,
void *data, size_t datalen)
{
...
memcpy(buffer, devcoredump_saved_buffer + offset, count);
...
}
and that example has a time complexity of O(N*2), where N is the size of the devcoredump. way better scaling than the previous example for larger devcoredumps β we love a glow-up π₯
π RETURN π
the drm_printer object. that's the whole vibe check result π
π SEE ALSO π
- Kernel file
./include/drm/drm_print.hprint(9) enum drm_debug_category(9)struct drm_printer(9)drm_vprintf(9)drm_printf_indent(9)struct drm_print_iterator(9)drm_coredump_printer_is_full(9)drm_seq_file_printer(9)drm_info_printer(9)drm_dbg_printer(9)drm_err_printer(9)drm_line_printer(9)DRM_DEV_ERROR(9)DRM_DEV_ERROR_RATELIMITED(9)DRM_DEV_DEBUG(9)DRM_DEV_DEBUG_DRIVER(9)DRM_DEV_DEBUG_KMS(9)
and that's the page, bestie π it came from ./include/drm, dated October 2026, and it's filed under drm_coredump_printer(9) β go forth and print your coredumps, mwah π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms