Linux Power Management development
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Harley A.W. Lorenzo" <hl1998@protonmail.com>,
	Sebastian Reichel <sre@kernel.org>
Cc: "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"wangxiongfeng2@huawei.com" <wangxiongfeng2@huawei.com>
Subject: Re: [PATCH] test_power: add missing newlines when printing parameters by sysfs
Date: Sun, 04 Oct 2020 21:19:15 -0700	[thread overview]
Message-ID: <f8fd76b81dab7dcb0e262a62e4d92bdf63ef2cfe.camel@perches.com> (raw)
In-Reply-To: <1g3ecQ7VLlrgKOSHr6teWgw9xcmVVQx1bFp2KpJD7y35lZpaC8ONb-jrPKapmFttEwVg2uhDwmv6mug9z5-GVZbqPbkOjcqjrSHtaW-k6ts=@protonmail.com>

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"));
}



  reply	other threads:[~2020-10-05  4:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04  6:09 [PATCH] test_power: add missing newlines when printing parameters by sysfs Xiongfeng Wang
2020-10-03 21:23 ` Sebastian Reichel
2020-10-03 21:43   ` Joe Perches
2020-10-03 21:50     ` Sebastian Reichel
2020-10-03 21:55       ` Joe Perches
2020-10-04 22:16         ` Sebastian Reichel
2020-10-05  1:30           ` Harley A.W. Lorenzo
2020-10-05  4:19             ` Joe Perches [this message]
2020-10-05  4:44               ` Harley A.W. Lorenzo
2020-10-08 23:07                 ` Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8fd76b81dab7dcb0e262a62e4d92bdf63ef2cfe.camel@perches.com \
    --to=joe@perches.com \
    --cc=hl1998@protonmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=wangxiongfeng2@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox