From 68bd9ea94afe6dbbb156de4d07c52acd541d70e1 Mon Sep 17 00:00:00 2001 From: jsg Date: Fri, 11 Oct 2024 02:33:11 +0000 Subject: [PATCH] drm/printer: Allow NULL data in devcoredump printer From Matthew Brost 4ee08b4a7201ba0f7f3d52e3840fee92f415b6c5 in linux-6.6.y/6.6.55 53369581dc0c68a5700ed51e1660f44c4b2bb524 in mainline linux --- sys/dev/pci/drm/drm_print.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/dev/pci/drm/drm_print.c b/sys/dev/pci/drm/drm_print.c index 68c810e2d7b..da63a054a0d 100644 --- a/sys/dev/pci/drm/drm_print.c +++ b/sys/dev/pci/drm/drm_print.c @@ -104,8 +104,9 @@ void __drm_puts_coredump(struct drm_printer *p, const char *str) copy = iterator->remain; /* Copy out the bit of the string that we need */ - memcpy(iterator->data, - str + (iterator->start - iterator->offset), copy); + if (iterator->data) + memcpy(iterator->data, + str + (iterator->start - iterator->offset), copy); iterator->offset = iterator->start + copy; iterator->remain -= copy; @@ -114,7 +115,8 @@ void __drm_puts_coredump(struct drm_printer *p, const char *str) len = min_t(ssize_t, strlen(str), iterator->remain); - memcpy(iterator->data + pos, str, len); + if (iterator->data) + memcpy(iterator->data + pos, str, len); iterator->offset += len; iterator->remain -= len; @@ -144,8 +146,9 @@ void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf) if ((iterator->offset >= iterator->start) && (len < iterator->remain)) { ssize_t pos = iterator->offset - iterator->start; - snprintf(((char *) iterator->data) + pos, - iterator->remain, "%pV", vaf); + if (iterator->data) + snprintf(((char *) iterator->data) + pos, + iterator->remain, "%pV", vaf); iterator->offset += len; iterator->remain -= len; -- 2.20.1