All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
@ 2020-07-20  2:03 Xiongfeng Wang
  2020-07-20 19:52 ` Corey Minyard
  0 siblings, 1 reply; 5+ messages in thread
From: Xiongfeng Wang @ 2020-07-20  2:03 UTC (permalink / raw)
  To: minyard, arnd, gregkh
  Cc: openipmi-developer, linux-kernel, guohanjun, wangxiongfeng2

When I cat some ipmi_watchdog parameters by sysfs, it displays as
follows. It's better to add a newline for easy reading.

root@(none):/# cat /sys/module/ipmi_watchdog/parameters/action
resetroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preaction
pre_noneroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preop
preop_noneroot@(none):/#

Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/char/ipmi/ipmi_watchdog.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 55986e1..3e05a1d 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
 static int get_param_str(char *buffer, const struct kernel_param *kp)
 {
 	action_fn fn = (action_fn) kp->arg;
-	int       rv;
+	int rv, len;
 
 	rv = fn(NULL, buffer);
 	if (rv)
 		return rv;
-	return strlen(buffer);
+
+	len = strlen(buffer);
+	len += sprintf(buffer + len, "\n");
+
+	return len;
 }
 
 
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
  2020-07-20  2:03 [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs Xiongfeng Wang
@ 2020-07-20 19:52 ` Corey Minyard
  2020-07-21  1:20   ` Xiongfeng Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Corey Minyard @ 2020-07-20 19:52 UTC (permalink / raw)
  To: Xiongfeng Wang; +Cc: arnd, gregkh, openipmi-developer, linux-kernel, guohanjun

On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote:
> When I cat some ipmi_watchdog parameters by sysfs, it displays as
> follows. It's better to add a newline for easy reading.
> 
> root@(none):/# cat /sys/module/ipmi_watchdog/parameters/action
> resetroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preaction
> pre_noneroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preop
> preop_noneroot@(none):/#

Yeah, that's not consistent with other things displayed in the kernel.

> 
> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> ---
>  drivers/char/ipmi/ipmi_watchdog.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
> index 55986e1..3e05a1d 100644
> --- a/drivers/char/ipmi/ipmi_watchdog.c
> +++ b/drivers/char/ipmi/ipmi_watchdog.c
> @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
>  static int get_param_str(char *buffer, const struct kernel_param *kp)
>  {
>  	action_fn fn = (action_fn) kp->arg;
> -	int       rv;
> +	int rv, len;
>  
>  	rv = fn(NULL, buffer);
>  	if (rv)
>  		return rv;
> -	return strlen(buffer);
> +
> +	len = strlen(buffer);
> +	len += sprintf(buffer + len, "\n");

sprintf is kind of overkill to stick a \n on the end of a line.  How
about:

	buffer[len++] = '\n';

Since you are returning the length, you shouldn't need to nil terminate
the string.

An unrelated question: Are you using any of the special functions of the
IPMI watchdog, like the pretimeout?

-corey

> +
> +	return len;
>  }
>  
>  
> -- 
> 1.7.12.4
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
  2020-07-20 19:52 ` Corey Minyard
@ 2020-07-21  1:20   ` Xiongfeng Wang
  2020-07-21  2:00     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Xiongfeng Wang @ 2020-07-21  1:20 UTC (permalink / raw)
  To: minyard; +Cc: arnd, gregkh, openipmi-developer, linux-kernel, guohanjun

Hi Corey,

Thanks for your reply !

On 2020/7/21 3:52, Corey Minyard wrote:
> On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote:
>> When I cat some ipmi_watchdog parameters by sysfs, it displays as
>> follows. It's better to add a newline for easy reading.
>>
>> root@(none):/# cat /sys/module/ipmi_watchdog/parameters/action
>> resetroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preaction
>> pre_noneroot@(none):/# cat /sys/module/ipmi_watchdog/parameters/preop
>> preop_noneroot@(none):/#
> 
> Yeah, that's not consistent with other things displayed in the kernel.
> 
>>
>> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
>> ---
>>  drivers/char/ipmi/ipmi_watchdog.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
>> index 55986e1..3e05a1d 100644
>> --- a/drivers/char/ipmi/ipmi_watchdog.c
>> +++ b/drivers/char/ipmi/ipmi_watchdog.c
>> @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
>>  static int get_param_str(char *buffer, const struct kernel_param *kp)
>>  {
>>  	action_fn fn = (action_fn) kp->arg;
>> -	int       rv;
>> +	int rv, len;
>>  
>>  	rv = fn(NULL, buffer);
>>  	if (rv)
>>  		return rv;
>> -	return strlen(buffer);
>> +
>> +	len = strlen(buffer);
>> +	len += sprintf(buffer + len, "\n");
> 
> sprintf is kind of overkill to stick a \n on the end of a line.  How
> about:
> 
> 	buffer[len++] = '\n';
> 
> Since you are returning the length, you shouldn't need to nil terminate
> the string.

Thanks for your advice. I will change it in the next version.

> 
> An unrelated question: Are you using any of the special functions of the
> IPMI watchdog, like the pretimeout?

I am not using any special functions of the IPMI watchdog. It's just that I cat
the parameters below 'ipmi_watchdog' and find we can add a newline here.

Thanks,
Xiongfeng

> 
> -corey
> 
>> +
>> +	return len;
>>  }
>>  
>>  
>> -- 
>> 1.7.12.4
>>
> 
> .
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
  2020-07-21  1:20   ` Xiongfeng Wang
@ 2020-07-21  2:00     ` Joe Perches
  2020-07-21  6:17       ` Xiongfeng Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2020-07-21  2:00 UTC (permalink / raw)
  To: Xiongfeng Wang, minyard
  Cc: arnd, gregkh, openipmi-developer, linux-kernel, guohanjun

On Tue, 2020-07-21 at 09:20 +0800, Xiongfeng Wang wrote:
> On 2020/7/21 3:52, Corey Minyard wrote:
> > On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote:
> > > When I cat some ipmi_watchdog parameters by sysfs, it displays as
> > > follows. It's better to add a newline for easy reading.
[]
> > > diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
[]
> > > @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
> > >  static int get_param_str(char *buffer, const struct kernel_param *kp)
> > >  {
> > >  	action_fn fn = (action_fn) kp->arg;
> > > -	int       rv;
> > > +	int rv, len;
> > >  
> > >  	rv = fn(NULL, buffer);
> > >  	if (rv)
> > >  		return rv;
> > > -	return strlen(buffer);
> > > +
> > > +	len = strlen(buffer);
> > > +	len += sprintf(buffer + len, "\n");
> > 
> > sprintf is kind of overkill to stick a \n on the end of a line.  How
> > about:
> > 
> > 	buffer[len++] = '\n';
> > 
> > Since you are returning the length, you shouldn't need to nil terminate
> > the string.

You never quite know for sure so I suggest making
the string null terminated just in case.

i.e.:

	buffer[len++] = '\n';
	buffer[len] = 0;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
  2020-07-21  2:00     ` Joe Perches
@ 2020-07-21  6:17       ` Xiongfeng Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Xiongfeng Wang @ 2020-07-21  6:17 UTC (permalink / raw)
  To: Joe Perches, minyard
  Cc: arnd, gregkh, openipmi-developer, linux-kernel, guohanjun



On 2020/7/21 10:00, Joe Perches wrote:
> On Tue, 2020-07-21 at 09:20 +0800, Xiongfeng Wang wrote:
>> On 2020/7/21 3:52, Corey Minyard wrote:
>>> On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote:
>>>> When I cat some ipmi_watchdog parameters by sysfs, it displays as
>>>> follows. It's better to add a newline for easy reading.
> []
>>>> diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
> []
>>>> @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
>>>>  static int get_param_str(char *buffer, const struct kernel_param *kp)
>>>>  {
>>>>  	action_fn fn = (action_fn) kp->arg;
>>>> -	int       rv;
>>>> +	int rv, len;
>>>>  
>>>>  	rv = fn(NULL, buffer);
>>>>  	if (rv)
>>>>  		return rv;
>>>> -	return strlen(buffer);
>>>> +
>>>> +	len = strlen(buffer);
>>>> +	len += sprintf(buffer + len, "\n");
>>>
>>> sprintf is kind of overkill to stick a \n on the end of a line.  How
>>> about:
>>>
>>> 	buffer[len++] = '\n';
>>>
>>> Since you are returning the length, you shouldn't need to nil terminate
>>> the string.
> 
> You never quite know for sure so I suggest making
> the string null terminated just in case.
> 
> i.e.:
> 
> 	buffer[len++] = '\n';
> 	buffer[len] = 0;
> 

Thanks for your advice. I will change it in the next version.

Thanks,
Xiongfeng

> 
> 
> .
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-21  6:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  2:03 [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs Xiongfeng Wang
2020-07-20 19:52 ` Corey Minyard
2020-07-21  1:20   ` Xiongfeng Wang
2020-07-21  2:00     ` Joe Perches
2020-07-21  6:17       ` Xiongfeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.