Re: [PATCH] printk: remove unnecessary kmalloc() from syslog during clear

From: Sergey Senozhatsky
Date: Thu Jun 21 2018 - 02:58:13 EST


On (06/20/18 19:26), Namit Gupta wrote:
[..]
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 512f7c2..53952ce 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1348,71 +1348,80 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
> {
> char *text;
> 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;
> + }

---

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4a07e7158898..33a1e45293a5 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1395,13 +1395,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
return 0;
}

-
text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
if (!text)
return -ENOMEM;

logbuf_lock_irq();
-
/*
* Find first record that fits, including all following records,
* into the user-provided buffer for this dump.
@@ -1436,7 +1434,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
int textlen;

textlen = msg_print_text(msg, true, text,
- LOG_LINE_MAX + PREFIX_MAX);
+ LOG_LINE_MAX + PREFIX_MAX);
if (textlen < 0) {
len = textlen;
break;
---


Other than that, looks OK to me.

Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>

-ss