lkml.org 
[lkml]   [2020]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] test_power: add missing newlines when printing parameters by sysfs
From
Date
On Mon, 2020-10-05 at 01:30 +0000, Harley A.W. Lorenzo wrote:
> Here is the updated patch using sprintf, diffing from the original patch by Xiongfeng Wang.
>
> [PATCH] test_power: revise parameter printing to use sprintf
>
> Signed-off-by: Harley A.W. Lorenzo <hl1998@protonmail.com>
> Suggested-by: Joe Perches <joe@perches.com>

I did not suggest this.

> diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
[]
> @@ -352,8 +352,8 @@ static int param_set_ac_online(const char *key, const struct kernel_param *kp)
>
> static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
> {.
> - strcpy(buffer, map_get_key(map_ac_online, ac_online, "unknown"));
> - strcat(buffer, "\n");
> + char const *out = map_get_key(map_ac_online, ac_online, "unknown");
> + sprintf(buffer, "%s\n", out);
> return strlen(buffer);
> }

No temporary is necessary nor is strlen as
that's the same as the return from sprintf.

All of these should be similar to:

static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
{
return sprintf(buffer, "%s\n",
map_get_key(map_ac_online, ac_online, "unknown"));
}


\
 
 \ /
  Last update: 2020-10-05 06:20    [W:0.059 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site