lkml.org 
[lkml]   [2020]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
From
Date


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

>
>
> .
>

\
 
 \ /
  Last update: 2020-07-21 08:18    [W:0.040 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site