[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f8fd76b81dab7dcb0e262a62e4d92bdf63ef2cfe.camel@perches.com>
Date: Sun, 04 Oct 2020 21:19:15 -0700
From: Joe Perches <joe@...ches.com>
To: "Harley A.W. Lorenzo" <hl1998@...tonmail.com>,
Sebastian Reichel <sre@...nel.org>
Cc: "linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"wangxiongfeng2@...wei.com" <wangxiongfeng2@...wei.com>
Subject: Re: [PATCH] test_power: add missing newlines when printing
parameters by sysfs
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@...tonmail.com>
> Suggested-by: Joe Perches <joe@...ches.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"));
}
Powered by blists - more mailing lists