diff mbox series

test_power: add missing newlines when printing parameters by sysfs

Message ID 1599199798-27804-1-git-send-email-wangxiongfeng2@huawei.com (mailing list archive)
State Not Applicable, archived
Headers show
Series test_power: add missing newlines when printing parameters by sysfs | expand

Commit Message

Xiongfeng Wang Sept. 4, 2020, 6:09 a.m. UTC
When I cat some module parameters by sysfs, it displays as follows.
It's better to add a newline for easy reading.

root@syzkaller:~# cd /sys/module/test_power/parameters/
root@syzkaller:/sys/module/test_power/parameters# cat ac_online
onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
onroot@syzkaller:/sys/module/test_power/parameters#

Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/power/supply/test_power.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Sebastian Reichel Oct. 3, 2020, 9:23 p.m. UTC | #1
Hi,

On Fri, Sep 04, 2020 at 02:09:58PM +0800, Xiongfeng Wang wrote:
> When I cat some module parameters by sysfs, it displays as follows.
> It's better to add a newline for easy reading.
> 
> root@syzkaller:~# cd /sys/module/test_power/parameters/
> root@syzkaller:/sys/module/test_power/parameters# cat ac_online
> onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
> trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
> goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
> dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
> LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
> onroot@syzkaller:/sys/module/test_power/parameters#
> 
> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/test_power.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> index 04acd76..4895ee5 100644
> --- a/drivers/power/supply/test_power.c
> +++ b/drivers/power/supply/test_power.c
> @@ -353,6 +353,7 @@ 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");
>  	return strlen(buffer);
>  }
>  
> @@ -366,6 +367,7 @@ static int param_set_usb_online(const char *key, const struct kernel_param *kp)
>  static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
>  {
>  	strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
> +	strcat(buffer, "\n");
>  	return strlen(buffer);
>  }
>  
> @@ -380,6 +382,7 @@ static int param_set_battery_status(const char *key,
>  static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
>  {
>  	strcpy(buffer, map_get_key(map_status, battery_status, "unknown"));
> +	strcat(buffer, "\n");
>  	return strlen(buffer);
>  }
>  
> @@ -394,6 +397,7 @@ static int param_set_battery_health(const char *key,
>  static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
>  {
>  	strcpy(buffer, map_get_key(map_health, battery_health, "unknown"));
> +	strcat(buffer, "\n");
>  	return strlen(buffer);
>  }
>  
> @@ -409,6 +413,7 @@ static int param_get_battery_present(char *buffer,
>  					const struct kernel_param *kp)
>  {
>  	strcpy(buffer, map_get_key(map_present, battery_present, "unknown"));
> +	strcat(buffer, "\n");
>  	return strlen(buffer);
>  }
>  
> @@ -426,6 +431,7 @@ static int param_get_battery_technology(char *buffer,
>  {
>  	strcpy(buffer,
>  		map_get_key(map_technology, battery_technology, "unknown"));
> +	strcat(buffer, "\n");
>  	return strlen(buffer);
>  }
>  
> -- 
> 1.7.12.4
>
Joe Perches Oct. 3, 2020, 9:43 p.m. UTC | #2
On Sat, 2020-10-03 at 23:23 +0200, Sebastian Reichel wrote:
> Hi,
> 
> On Fri, Sep 04, 2020 at 02:09:58PM +0800, Xiongfeng Wang wrote:
> > When I cat some module parameters by sysfs, it displays as follows.
> > It's better to add a newline for easy reading.
[]
> > root@syzkaller:~# cd /sys/module/test_power/parameters/
> > root@syzkaller:/sys/module/test_power/parameters# cat ac_online
> > onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
> > trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
> > goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
> > dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
> > LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
> > onroot@syzkaller:/sys/module/test_power/parameters#
> > 
> > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > ---
> 
> Thanks, queued.
[]
> > diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
[]
> > @@ -353,6 +353,7 @@ 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");
> >  	return strlen(buffer);
> >  }

All of these would be better as sprintf(buffer, "%s\n", <whatever>)
so the output is scanned just once instead of scanned three times.
Sebastian Reichel Oct. 3, 2020, 9:50 p.m. UTC | #3
Hi,

On Sat, Oct 03, 2020 at 02:43:09PM -0700, Joe Perches wrote:
> On Sat, 2020-10-03 at 23:23 +0200, Sebastian Reichel wrote:
> > On Fri, Sep 04, 2020 at 02:09:58PM +0800, Xiongfeng Wang wrote:
> > > When I cat some module parameters by sysfs, it displays as follows.
> > > It's better to add a newline for easy reading.
> []
> > > root@syzkaller:~# cd /sys/module/test_power/parameters/
> > > root@syzkaller:/sys/module/test_power/parameters# cat ac_online
> > > onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
> > > trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
> > > goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
> > > dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
> > > LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
> > > onroot@syzkaller:/sys/module/test_power/parameters#
> > > 
> > > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > > ---
> > 
> > Thanks, queued.
> []
> > > diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> []
> > > @@ -353,6 +353,7 @@ 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");
> > >  	return strlen(buffer);
> > >  }
> 
> All of these would be better as sprintf(buffer, "%s\n", <whatever>)
> so the output is scanned just once instead of scanned three times.

Agreed. Anybody willing to send a patch? :)

-- Sebastian
Joe Perches Oct. 3, 2020, 9:55 p.m. UTC | #4
On Sat, 2020-10-03 at 23:50 +0200, Sebastian Reichel wrote:
> Hi,
> 
> On Sat, Oct 03, 2020 at 02:43:09PM -0700, Joe Perches wrote:
> > On Sat, 2020-10-03 at 23:23 +0200, Sebastian Reichel wrote:
> > > On Fri, Sep 04, 2020 at 02:09:58PM +0800, Xiongfeng Wang wrote:
> > > > When I cat some module parameters by sysfs, it displays as follows.
> > > > It's better to add a newline for easy reading.
> > []
> > > > root@syzkaller:~# cd /sys/module/test_power/parameters/
> > > > root@syzkaller:/sys/module/test_power/parameters# cat ac_online
> > > > onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
> > > > trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
> > > > goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
> > > > dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
> > > > LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
> > > > onroot@syzkaller:/sys/module/test_power/parameters#
> > > > 
> > > > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > > > ---
> > > 
> > > Thanks, queued.
> > []
> > > > diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> > []
> > > > @@ -353,6 +353,7 @@ 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");
> > > >  	return strlen(buffer);
> > > >  }
> > 
> > All of these would be better as sprintf(buffer, "%s\n", <whatever>)
> > so the output is scanned just once instead of scanned three times.
> 
> Agreed. Anybody willing to send a patch? :)

Well, you _are_ the maintainer. Why not you?
Sebastian Reichel Oct. 4, 2020, 10:16 p.m. UTC | #5
Hi,

On Sat, Oct 03, 2020 at 02:55:41PM -0700, Joe Perches wrote:
> On Sat, 2020-10-03 at 23:50 +0200, Sebastian Reichel wrote:
> > Hi,
> > 
> > On Sat, Oct 03, 2020 at 02:43:09PM -0700, Joe Perches wrote:
> > > On Sat, 2020-10-03 at 23:23 +0200, Sebastian Reichel wrote:
> > > > On Fri, Sep 04, 2020 at 02:09:58PM +0800, Xiongfeng Wang wrote:
> > > > > When I cat some module parameters by sysfs, it displays as follows.
> > > > > It's better to add a newline for easy reading.
> > > []
> > > > > root@syzkaller:~# cd /sys/module/test_power/parameters/
> > > > > root@syzkaller:/sys/module/test_power/parameters# cat ac_online
> > > > > onroot@syzkaller:/sys/module/test_power/parameters# cat battery_present
> > > > > trueroot@syzkaller:/sys/module/test_power/parameters# cat battery_health
> > > > > goodroot@syzkaller:/sys/module/test_power/parameters# cat battery_status
> > > > > dischargingroot@syzkaller:/sys/module/test_power/parameters# cat battery_technology
> > > > > LIONroot@syzkaller:/sys/module/test_power/parameters# cat usb_online
> > > > > onroot@syzkaller:/sys/module/test_power/parameters#
> > > > > 
> > > > > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > > > > ---
> > > > 
> > > > Thanks, queued.
> > > []
> > > > > diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> > > []
> > > > > @@ -353,6 +353,7 @@ 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");
> > > > >  	return strlen(buffer);
> > > > >  }
> > > 
> > > All of these would be better as sprintf(buffer, "%s\n", <whatever>)
> > > so the output is scanned just once instead of scanned three times.
> > 
> > Agreed. Anybody willing to send a patch? :)
> 
> Well, you _are_ the maintainer. Why not you?

I prefer to have patches reviewed and when I sent out patches for
my own subsystem I often do not get any reviews at all. From my
experience people often like to increase their patch count anyways
(e.g. because their employer wanting to see high patch count), so
asking others to write the patch is an easy workaround for me. I
then only do the leftovers.

-- Sebastian
Harley A.W. Lorenzo Oct. 5, 2020, 1:30 a.m. UTC | #6
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>
---
 drivers/power/supply/test_power.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 4895ee5e63a9..fbb179a1b615 100644
--- 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);
 }

@@ -366,8 +366,8 @@ static int param_set_usb_online(const char *key, const struct kernel_param *kp)

 static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
-	strcat(buffer, "\n");
+	char const *out = map_get_key(map_ac_online, usb_online, "unknown");
+	sprintf(buffer, "%s\n", out);
 	return strlen(buffer);
 }

@@ -381,8 +381,8 @@ static int param_set_battery_status(const char *key,

 static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_status, battery_status, "unknown"));
-	strcat(buffer, "\n");
+	char const *out = map_get_key(map_ac_online, battery_status, "unknown");
+	sprintf(buffer, "%s\n", out);
 	return strlen(buffer);
 }

@@ -396,8 +396,8 @@ static int param_set_battery_health(const char *key,

 static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_health, battery_health, "unknown"));
-	strcat(buffer, "\n");
+	char const *out = map_get_key(map_ac_online, battery_health, "unknown");
+	sprintf(buffer, "%s\n", out);
 	return strlen(buffer);
 }

@@ -412,8 +412,9 @@ static int param_set_battery_present(const char *key,
 static int param_get_battery_present(char *buffer,
 					const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_present, battery_present, "unknown"));
-	strcat(buffer, "\n");
+	char const *out = map_get_key(map_ac_online, battery_present,
+					"unknown");
+	sprintf(buffer, "%s\n", out);
 	return strlen(buffer);
 }

@@ -429,9 +430,9 @@ static int param_set_battery_technology(const char *key,
 static int param_get_battery_technology(char *buffer,
 					const struct kernel_param *kp)
 {
-	strcpy(buffer,
-		map_get_key(map_technology, battery_technology, "unknown"));
-	strcat(buffer, "\n");
+	char const *out = map_get_key(map_ac_online, battery_technology,
+					"unknown");
+	sprintf(buffer, "%s\n", out);
 	return strlen(buffer);
 }

--
2.28.0
Joe Perches Oct. 5, 2020, 4:19 a.m. UTC | #7
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"));
}
Harley A.W. Lorenzo Oct. 5, 2020, 4:44 a.m. UTC | #8
On Monday, October 5, 2020 12:19 AM, Joe Perches <joe@perches.com> wrote:
> I did not suggest this.

My apologies. Revised patch (still diffing from Xiongfeng Wang) here.

[PATCH v2] 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>
---
 drivers/power/supply/test_power.c | 32 +++++++++++++------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 4895ee5e63a9..5f510ddc946d 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -352,9 +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");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, ac_online, "unknown"));
 }

 static int param_set_usb_online(const char *key, const struct kernel_param *kp)
@@ -366,9 +365,8 @@ static int param_set_usb_online(const char *key, const struct kernel_param *kp)

 static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
-	strcat(buffer, "\n");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, usb_online, "unknown"));
 }

 static int param_set_battery_status(const char *key,
@@ -381,9 +379,8 @@ static int param_set_battery_status(const char *key,

 static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_status, battery_status, "unknown"));
-	strcat(buffer, "\n");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, battery_status, "unknown"));
 }

 static int param_set_battery_health(const char *key,
@@ -396,9 +393,8 @@ static int param_set_battery_health(const char *key,

 static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_health, battery_health, "unknown"));
-	strcat(buffer, "\n");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, battery_health, "unknown"));
 }

 static int param_set_battery_present(const char *key,
@@ -412,9 +408,8 @@ static int param_set_battery_present(const char *key,
 static int param_get_battery_present(char *buffer,
 					const struct kernel_param *kp)
 {
-	strcpy(buffer, map_get_key(map_present, battery_present, "unknown"));
-	strcat(buffer, "\n");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, battery_present, "unknown"));
 }

 static int param_set_battery_technology(const char *key,
@@ -429,10 +424,9 @@ static int param_set_battery_technology(const char *key,
 static int param_get_battery_technology(char *buffer,
 					const struct kernel_param *kp)
 {
-	strcpy(buffer,
-		map_get_key(map_technology, battery_technology, "unknown"));
-	strcat(buffer, "\n");
-	return strlen(buffer);
+	return sprintf(buffer, "%s\n",
+			map_get_key(map_ac_online, battery_technology,
+					"unknown"));
 }

 static int param_set_battery_capacity(const char *key,
--
2.28.0
Sebastian Reichel Oct. 8, 2020, 11:07 p.m. UTC | #9
Hi,

On Mon, Oct 05, 2020 at 04:44:17AM +0000, Harley A.W. Lorenzo wrote:
> On Monday, October 5, 2020 12:19 AM, Joe Perches <joe@perches.com> wrote:
> > I did not suggest this.
> 
> My apologies. Revised patch (still diffing from Xiongfeng Wang) here.
> 
> [PATCH v2] 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>
> ---

Thanks, I fixed the commit message and applied this.

-- Sebastian

>  drivers/power/supply/test_power.c | 32 +++++++++++++------------------
>  1 file changed, 13 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> index 4895ee5e63a9..5f510ddc946d 100644
> --- a/drivers/power/supply/test_power.c
> +++ b/drivers/power/supply/test_power.c
> @@ -352,9 +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");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, ac_online, "unknown"));
>  }
> 
>  static int param_set_usb_online(const char *key, const struct kernel_param *kp)
> @@ -366,9 +365,8 @@ static int param_set_usb_online(const char *key, const struct kernel_param *kp)
> 
>  static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
>  {
> -	strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
> -	strcat(buffer, "\n");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, usb_online, "unknown"));
>  }
> 
>  static int param_set_battery_status(const char *key,
> @@ -381,9 +379,8 @@ static int param_set_battery_status(const char *key,
> 
>  static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
>  {
> -	strcpy(buffer, map_get_key(map_status, battery_status, "unknown"));
> -	strcat(buffer, "\n");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, battery_status, "unknown"));
>  }
> 
>  static int param_set_battery_health(const char *key,
> @@ -396,9 +393,8 @@ static int param_set_battery_health(const char *key,
> 
>  static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
>  {
> -	strcpy(buffer, map_get_key(map_health, battery_health, "unknown"));
> -	strcat(buffer, "\n");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, battery_health, "unknown"));
>  }
> 
>  static int param_set_battery_present(const char *key,
> @@ -412,9 +408,8 @@ static int param_set_battery_present(const char *key,
>  static int param_get_battery_present(char *buffer,
>  					const struct kernel_param *kp)
>  {
> -	strcpy(buffer, map_get_key(map_present, battery_present, "unknown"));
> -	strcat(buffer, "\n");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, battery_present, "unknown"));
>  }
> 
>  static int param_set_battery_technology(const char *key,
> @@ -429,10 +424,9 @@ static int param_set_battery_technology(const char *key,
>  static int param_get_battery_technology(char *buffer,
>  					const struct kernel_param *kp)
>  {
> -	strcpy(buffer,
> -		map_get_key(map_technology, battery_technology, "unknown"));
> -	strcat(buffer, "\n");
> -	return strlen(buffer);
> +	return sprintf(buffer, "%s\n",
> +			map_get_key(map_ac_online, battery_technology,
> +					"unknown"));
>  }
> 
>  static int param_set_battery_capacity(const char *key,
> --
> 2.28.0
diff mbox series

Patch

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 04acd76..4895ee5 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -353,6 +353,7 @@  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");
 	return strlen(buffer);
 }
 
@@ -366,6 +367,7 @@  static int param_set_usb_online(const char *key, const struct kernel_param *kp)
 static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
 {
 	strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
+	strcat(buffer, "\n");
 	return strlen(buffer);
 }
 
@@ -380,6 +382,7 @@  static int param_set_battery_status(const char *key,
 static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
 {
 	strcpy(buffer, map_get_key(map_status, battery_status, "unknown"));
+	strcat(buffer, "\n");
 	return strlen(buffer);
 }
 
@@ -394,6 +397,7 @@  static int param_set_battery_health(const char *key,
 static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
 {
 	strcpy(buffer, map_get_key(map_health, battery_health, "unknown"));
+	strcat(buffer, "\n");
 	return strlen(buffer);
 }
 
@@ -409,6 +413,7 @@  static int param_get_battery_present(char *buffer,
 					const struct kernel_param *kp)
 {
 	strcpy(buffer, map_get_key(map_present, battery_present, "unknown"));
+	strcat(buffer, "\n");
 	return strlen(buffer);
 }
 
@@ -426,6 +431,7 @@  static int param_get_battery_technology(char *buffer,
 {
 	strcpy(buffer,
 		map_get_key(map_technology, battery_technology, "unknown"));
+	strcat(buffer, "\n");
 	return strlen(buffer);
 }