diff mbox series

[RE-SEND,v1] PM / devfreq: Replace strncpy with strscpy

Message ID 20200227170854.9949-1-digetx@gmail.com
State Accepted
Delegated to: Chanwoo Choi
Headers show
Series [RE-SEND,v1] PM / devfreq: Replace strncpy with strscpy | expand

Commit Message

Dmitry Osipenko Feb. 27, 2020, 5:08 p.m. UTC
GCC produces this warning when kernel compiled using `make W=1`:

  warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
  772 |  strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);

The strncpy doesn't take care of NULL-termination of the destination
buffer, while the strscpy does.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dmitry Osipenko April 17, 2020, 2:04 p.m. UTC | #1
27.02.2020 20:08, Dmitry Osipenko пишет:
> GCC produces this warning when kernel compiled using `make W=1`:
> 
>   warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
>   772 |  strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
> 
> The strncpy doesn't take care of NULL-termination of the destination
> buffer, while the strscpy does.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/devfreq/devfreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 8494c5f05a73..2011f64bfa3a 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -769,7 +769,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>  	devfreq->dev.release = devfreq_dev_release;
>  	INIT_LIST_HEAD(&devfreq->node);
>  	devfreq->profile = profile;
> -	strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
> +	strscpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>  	devfreq->previous_freq = profile->initial_freq;
>  	devfreq->last_status.current_frequency = profile->initial_freq;
>  	devfreq->data = data;
> 

Hello Chanwoo,

Do you have any objections to this patch?
Chanwoo Choi May 7, 2020, 12:02 a.m. UTC | #2
Hi Dmitry,

On 4/17/20 11:04 PM, Dmitry Osipenko wrote:
> 27.02.2020 20:08, Dmitry Osipenko пишет:
>> GCC produces this warning when kernel compiled using `make W=1`:
>>
>>   warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
>>   772 |  strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>>
>> The strncpy doesn't take care of NULL-termination of the destination
>> buffer, while the strscpy does.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  drivers/devfreq/devfreq.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>> index 8494c5f05a73..2011f64bfa3a 100644
>> --- a/drivers/devfreq/devfreq.c
>> +++ b/drivers/devfreq/devfreq.c
>> @@ -769,7 +769,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>  	devfreq->dev.release = devfreq_dev_release;
>>  	INIT_LIST_HEAD(&devfreq->node);
>>  	devfreq->profile = profile;
>> -	strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>> +	strscpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>>  	devfreq->previous_freq = profile->initial_freq;
>>  	devfreq->last_status.current_frequency = profile->initial_freq;
>>  	devfreq->data = data;
>>
> 
> Hello Chanwoo,
> 
> Do you have any objections to this patch?
> 

I'm sorry for late reply. I applied it for v5.8-rc1.
Thanks.
Dmitry Osipenko May 7, 2020, 1 a.m. UTC | #3
07.05.2020 03:02, Chanwoo Choi пишет:
> Hi Dmitry,
> 
> On 4/17/20 11:04 PM, Dmitry Osipenko wrote:
>> 27.02.2020 20:08, Dmitry Osipenko пишет:
>>> GCC produces this warning when kernel compiled using `make W=1`:
>>>
>>>   warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
>>>   772 |  strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>>>
>>> The strncpy doesn't take care of NULL-termination of the destination
>>> buffer, while the strscpy does.
>>>
>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>> ---
>>>  drivers/devfreq/devfreq.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>>> index 8494c5f05a73..2011f64bfa3a 100644
>>> --- a/drivers/devfreq/devfreq.c
>>> +++ b/drivers/devfreq/devfreq.c
>>> @@ -769,7 +769,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>>>  	devfreq->dev.release = devfreq_dev_release;
>>>  	INIT_LIST_HEAD(&devfreq->node);
>>>  	devfreq->profile = profile;
>>> -	strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>>> +	strscpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
>>>  	devfreq->previous_freq = profile->initial_freq;
>>>  	devfreq->last_status.current_frequency = profile->initial_freq;
>>>  	devfreq->data = data;
>>>
>>
>> Hello Chanwoo,
>>
>> Do you have any objections to this patch?
>>
> 
> I'm sorry for late reply. I applied it for v5.8-rc1.
> Thanks.

No problems, thank you :)
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 8494c5f05a73..2011f64bfa3a 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -769,7 +769,7 @@  struct devfreq *devfreq_add_device(struct device *dev,
 	devfreq->dev.release = devfreq_dev_release;
 	INIT_LIST_HEAD(&devfreq->node);
 	devfreq->profile = profile;
-	strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
+	strscpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
 	devfreq->previous_freq = profile->initial_freq;
 	devfreq->last_status.current_frequency = profile->initial_freq;
 	devfreq->data = data;