From 874d1dc60d8999d56d304accff7f226bc36a3558 Mon Sep 17 00:00:00 2001 From: Ksawlii Date: Sun, 24 Nov 2024 00:23:06 +0100 Subject: [PATCH] Revert "drm/printer: Allow NULL data in devcoredump printer" This reverts commit f39aaded936b97249340e6396ad52d4e4398092b. --- drivers/gpu/drm/drm_print.c | 13 ++++----- include/drm/drm_print.h | 54 +------------------------------------ 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index 05c360c08..adebefa0c 100755 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -78,9 +78,8 @@ void __drm_puts_coredump(struct drm_printer *p, const char *str) copy = iterator->remain; /* Copy out the bit of the string that we need */ - if (iterator->data) - memcpy(iterator->data, - str + (iterator->start - iterator->offset), copy); + memcpy(iterator->data, + str + (iterator->start - iterator->offset), copy); iterator->offset = iterator->start + copy; iterator->remain -= copy; @@ -89,8 +88,7 @@ void __drm_puts_coredump(struct drm_printer *p, const char *str) len = min_t(ssize_t, strlen(str), iterator->remain); - if (iterator->data) - memcpy(iterator->data + pos, str, len); + memcpy(iterator->data + pos, str, len); iterator->offset += len; iterator->remain -= len; @@ -120,9 +118,8 @@ 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; - if (iterator->data) - snprintf(((char *) iterator->data) + pos, - iterator->remain, "%pV", vaf); + snprintf(((char *) iterator->data) + pos, + iterator->remain, "%pV", vaf); iterator->offset += len; iterator->remain -= len; diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index c0f5c9327..9214e5d84 100755 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -126,8 +126,7 @@ drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va) /** * struct drm_print_iterator - local struct used with drm_printer_coredump - * @data: Pointer to the devcoredump output buffer, can be NULL if using - * drm_printer_coredump to determine size of devcoredump + * @data: Pointer to the devcoredump output buffer * @start: The offset within the buffer to start writing * @remain: The number of bytes to write for this iteration */ @@ -172,57 +171,6 @@ struct drm_print_iterator { * coredump_read, ...) * } * - * The above example has a time complexity of O(N^2), where N is the size of the - * devcoredump. This is acceptable for small devcoredumps but scales poorly for - * larger ones. - * - * Another use case for drm_coredump_printer is to capture the devcoredump into - * a saved buffer before the dev_coredump() callback. This involves two passes: - * one to determine the size of the devcoredump and another to print it to a - * buffer. Then, in dev_coredump(), copy from the saved buffer into the - * devcoredump read buffer. - * - * 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=%d\n", 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); - * ... - * } - * - * The above example has a time complexity of O(N*2), where N is the size of the - * devcoredump. This scales better than the previous example for larger - * devcoredumps. - * * RETURNS: * The &drm_printer object */