Revert "drm/printer: Allow NULL data in devcoredump printer"

This reverts commit f39aaded93.
This commit is contained in:
Ksawlii 2024-11-24 00:23:06 +01:00
parent c721010d2d
commit 874d1dc60d
2 changed files with 6 additions and 61 deletions

View file

@ -78,9 +78,8 @@ void __drm_puts_coredump(struct drm_printer *p, const char *str)
copy = iterator->remain; copy = iterator->remain;
/* Copy out the bit of the string that we need */ /* Copy out the bit of the string that we need */
if (iterator->data) memcpy(iterator->data,
memcpy(iterator->data, str + (iterator->start - iterator->offset), copy);
str + (iterator->start - iterator->offset), copy);
iterator->offset = iterator->start + copy; iterator->offset = iterator->start + copy;
iterator->remain -= 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); 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->offset += len;
iterator->remain -= 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)) { if ((iterator->offset >= iterator->start) && (len < iterator->remain)) {
ssize_t pos = iterator->offset - iterator->start; ssize_t pos = iterator->offset - iterator->start;
if (iterator->data) snprintf(((char *) iterator->data) + pos,
snprintf(((char *) iterator->data) + pos, iterator->remain, "%pV", vaf);
iterator->remain, "%pV", vaf);
iterator->offset += len; iterator->offset += len;
iterator->remain -= len; iterator->remain -= len;

View file

@ -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 * struct drm_print_iterator - local struct used with drm_printer_coredump
* @data: Pointer to the devcoredump output buffer, can be NULL if using * @data: Pointer to the devcoredump output buffer
* drm_printer_coredump to determine size of devcoredump
* @start: The offset within the buffer to start writing * @start: The offset within the buffer to start writing
* @remain: The number of bytes to write for this iteration * @remain: The number of bytes to write for this iteration
*/ */
@ -172,57 +171,6 @@ struct drm_print_iterator {
* coredump_read, ...) * 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: * RETURNS:
* The &drm_printer object * The &drm_printer object
*/ */