From: Łukasz Stelmach Date: Tue, 13 Apr 2021 10:24:38 +0000 (+0200) Subject: logger: return amount of data written to stdio X-Git-Tag: accepted/tizen/unified/20210419.153507~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0bd63d18aa6237a40912ce2cdda7a358ebf87520;p=platform%2Fkernel%2Flinux-rpi.git logger: return amount of data written to stdio Return amount of data written by a process to a logger via STDIO interface. Change-Id: I9c77a312d09f3d796a7ec64d5909af193bcc8bc2 Signed-off-by: Łukasz Stelmach --- diff --git a/drivers/staging/android/logger.c b/drivers/staging/android/logger.c index 197b9c5..7983e57 100644 --- a/drivers/staging/android/logger.c +++ b/drivers/staging/android/logger.c @@ -592,7 +592,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) /* Prepend messages from STDOUT and STDERR with a tag and prio */ if (from_stdio) { char *p; - size_t chunk_len = 0; + size_t chunk_len = 0, c = 0; /* -2 : priority byte and tag terminating '\0' */ size_t max_payload = LOGGER_ENTRY_MAX_PAYLOAD - writer->tag_len - 2; @@ -624,30 +624,31 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) if (writer->b_owner != current && writer->b_off) flush_thread_data(file); + count = 0; /* -1 : leave space for message terminating '\0' */ - count = min_t(size_t, iov_iter_count(from), - max_payload - writer->b_off - 1); + c = min_t(size_t, iov_iter_count(from), + max_payload - writer->b_off - 1); do { - if (copy_from_iter(writer->buffer + writer->b_off, count, from) != count) { + if (copy_from_iter(writer->buffer + writer->b_off, c, from) != c) { mutex_unlock(&log->mutex); return -EFAULT; } - + count += c; /* TODO: replace NULL characters with new lines */ - p = strnrchr(writer->buffer + writer->b_off, count, '\n'); + p = strnrchr(writer->buffer + writer->b_off, c, '\n'); if (p) { *p++ = '\0'; chunk_len = p - writer->buffer; } else { - writer->buffer[writer->b_off + count++] = '\0'; - p = &writer->buffer[writer->b_off + count]; + writer->buffer[writer->b_off + c++] = '\0'; + p = &writer->buffer[writer->b_off + c]; chunk_len = p - writer->buffer; BUG_ON(chunk_len > max_payload); if (chunk_len < max_payload ) { - writer->b_off = writer->b_off + count - 1; + writer->b_off = writer->b_off + c - 1; continue; } @@ -659,13 +660,13 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) write_log_data(log, &header, writer, chunk_len); /* move the remaining part of the message */ - memmove(writer->buffer, p, writer->b_off + count - chunk_len); + memmove(writer->buffer, p, writer->b_off + c - chunk_len); /* new b_off points where the rimainder of the string ends */ - writer->b_off = writer->b_off + count - chunk_len; + writer->b_off = writer->b_off + c - chunk_len; writer->buffer[writer->b_off] = '\0'; - } while ((count = min_t(size_t, iov_iter_count(from), max_payload - 1))); + } while ((c = min_t(size_t, iov_iter_count(from), max_payload - 1))); /* save for remaining unfinished line */ writer->b_header = header;