Commit 63842c21 authored by Namit Gupta's avatar Namit Gupta Committed by Petr Mladek

printk: Remove unnecessary kmalloc() from syslog during clear

When the request is only for clearing logs, there is no need for
allocation/deallocation. Only the indexes need to be reset and returned.
Rest of the patch is mostly made up of changes because of indention.

Link: http://lkml.kernel.org/r/20180620135951epcas5p3bd2a8f25ec689ca333bce861b527dba2~54wyKcT0_3155531555epcas5p3y@epcas5p3.samsung.com
Cc: linux-kernel@vger.kernel.org
Cc: pankaj.m@samsung.com
Cc: a.sahrawat@samsung.com
Signed-off-by: default avatarNamit Gupta <gupta.namit@samsung.com>
Signed-off-by: default avatarHimanshu Maithani <himanshu.m@samsung.com>
Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
parent 22eceb8b
...@@ -1352,71 +1352,78 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -1352,71 +1352,78 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
{ {
char *text; char *text;
int len = 0; int len = 0;
u64 next_seq;
u64 seq;
u32 idx;
if (!buf) {
if (clear) {
logbuf_lock_irq();
clear_seq = log_next_seq;
clear_idx = log_next_idx;
logbuf_unlock_irq();
}
return 0;
}
text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL); text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
if (!text) if (!text)
return -ENOMEM; return -ENOMEM;
logbuf_lock_irq(); logbuf_lock_irq();
if (buf) { /*
u64 next_seq; * Find first record that fits, including all following records,
u64 seq; * into the user-provided buffer for this dump.
u32 idx; */
seq = clear_seq;
idx = clear_idx;
while (seq < log_next_seq) {
struct printk_log *msg = log_from_idx(idx);
/* len += msg_print_text(msg, true, NULL, 0);
* Find first record that fits, including all following records, idx = log_next(idx);
* into the user-provided buffer for this dump. seq++;
*/ }
seq = clear_seq;
idx = clear_idx;
while (seq < log_next_seq) {
struct printk_log *msg = log_from_idx(idx);
len += msg_print_text(msg, true, NULL, 0);
idx = log_next(idx);
seq++;
}
/* move first record forward until length fits into the buffer */ /* move first record forward until length fits into the buffer */
seq = clear_seq; seq = clear_seq;
idx = clear_idx; idx = clear_idx;
while (len > size && seq < log_next_seq) { while (len > size && seq < log_next_seq) {
struct printk_log *msg = log_from_idx(idx); struct printk_log *msg = log_from_idx(idx);
len -= msg_print_text(msg, true, NULL, 0); len -= msg_print_text(msg, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
} }
/* last message fitting into this dump */ /* last message fitting into this dump */
next_seq = log_next_seq; next_seq = log_next_seq;
len = 0; len = 0;
while (len >= 0 && seq < next_seq) { while (len >= 0 && seq < next_seq) {
struct printk_log *msg = log_from_idx(idx); struct printk_log *msg = log_from_idx(idx);
int textlen; int textlen;
textlen = msg_print_text(msg, true, text, textlen = msg_print_text(msg, true, text,
LOG_LINE_MAX + PREFIX_MAX); LOG_LINE_MAX + PREFIX_MAX);
if (textlen < 0) { if (textlen < 0) {
len = textlen; len = textlen;
break; break;
} }
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
logbuf_unlock_irq(); logbuf_unlock_irq();
if (copy_to_user(buf + len, text, textlen)) if (copy_to_user(buf + len, text, textlen))
len = -EFAULT; len = -EFAULT;
else else
len += textlen; len += textlen;
logbuf_lock_irq(); logbuf_lock_irq();
if (seq < log_first_seq) { if (seq < log_first_seq) {
/* messages are gone, move to next one */ /* messages are gone, move to next one */
seq = log_first_seq; seq = log_first_seq;
idx = log_first_idx; idx = log_first_idx;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment