Skip to content

Commit

Permalink
printk: Clean up syslog_print_all()
Browse files Browse the repository at this point in the history
syslog_print_all() is called twice. Once with a valid buffer
and once just to set the indexes.

Both variants are already handled separately. This patch just
makes it more obvious. It does not change the existing behavior.

Link: http://lkml.kernel.org/r/20180627150641.p56xyy6mdzvnfpig@pathway.suse.cz
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Namit Gupta <gupta.namit@samsung.com>
Cc: linux-kernel@vger.kernel.org
Cc: pankaj.m@samsung.com
Cc: a.sahrawat@samsung.com
Cc: himanshu.m@samsung.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
  • Loading branch information
pmladek committed Jul 9, 2018
1 parent 63842c2 commit 8599dc7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions kernel/printk/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,16 +1356,6 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
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);
if (!text)
return -ENOMEM;
Expand Down Expand Up @@ -1437,6 +1427,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
return len;
}

static void syslog_clear(void)
{
logbuf_lock_irq();
clear_seq = log_next_seq;
clear_idx = log_next_idx;
logbuf_unlock_irq();
}

int do_syslog(int type, char __user *buf, int len, int source)
{
bool clear = false;
Expand Down Expand Up @@ -1481,7 +1479,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
break;
/* Clear ring buffer */
case SYSLOG_ACTION_CLEAR:
syslog_print_all(NULL, 0, true);
syslog_clear();
break;
/* Disable logging to console */
case SYSLOG_ACTION_CONSOLE_OFF:
Expand Down

0 comments on commit 8599dc7

Please sign in to comment.