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 <hl1...@protonmail.com>
> Suggested-by: Joe Perches <j...@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"));
}


Reply via email to