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

From: Petr Mladek
Date: Mon Jun 25 2018 - 09:37:12 EST


On Wed 2018-06-20 19:26:19, Namit Gupta wrote:
> 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.
>
> Signed-off-by: Namit Gupta <gupta.namit@xxxxxxxxxxx>
> Signed-off-by: Himanshu Maithani <himanshu.m@xxxxxxxxxxx>

> ---
> kernel/printk/printk.c | 111 ++++++++++++++++++++++++++-----------------------
> 1 file changed, 60 insertions(+), 51 deletions(-)
>
> 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();

I pushed a bit different version into printk.git, branch for-4.19,
see below. It removes the code duplication. Also it keeps the original
indentation. IMHO, it helped to better distinguish the code for printing
and clearing.

It is rather a cosmetic change, so I do not want you to resend
Reviewed-by tags. But feel free to disagree and ask me to use
the original variant.


This is in printk.git now: