drm/printer: Allow NULL data in devcoredump printer
authorjsg <jsg@openbsd.org>
Fri, 11 Oct 2024 02:33:11 +0000 (02:33 +0000)
committerjsg <jsg@openbsd.org>
Fri, 11 Oct 2024 02:33:11 +0000 (02:33 +0000)
From Matthew Brost
4ee08b4a7201ba0f7f3d52e3840fee92f415b6c5 in linux-6.6.y/6.6.55
53369581dc0c68a5700ed51e1660f44c4b2bb524 in mainline linux

sys/dev/pci/drm/drm_print.c

index 68c810e..da63a05 100644 (file)
@@ -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;