Skip to contentSkip to conversation

PM / devfreq: Replace strncpy with strscpy

PATCH In review Dmitry Osipenko 2 participants 4 messages Feb 27, 2020 – May 7, 2020 Device frequency (devfreq)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: Replace strncpy with strscpy

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.

---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +1 -1
index 8494c5f05a73..2011f64bfa3a 100644
@@ -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;
Signature · 1 line
2.24.0
#1 lore raw

27.02.2020 20:08, Dmitry Osipenko пишет:

Quoted 19 lines

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.

---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +0 -0
index 8494c5f05a73..2011f64bfa3a 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 775

Quoted 8 lines
drivers/devfreq/devfreq.c +1 -1
@@ -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?

maintainer
#2 lore raw

Hi Dmitry,

Quoted 31 lines · Dmitry Osipenko

27.02.2020 20:08, Dmitry Osipenko пишет:

Quoted 19 lines

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.

---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +0 -0
index 8494c5f05a73..2011f64bfa3a 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 775

Quoted 8 lines
drivers/devfreq/devfreq.c +1 -1
@@ -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,

Quoted 2 lines

Do you have any objections to this patch?

I'm sorry for late reply. I applied it for v5.8-rc1. Thanks.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#3 lore raw

07.05.2020 03:02, Chanwoo Choi пишет:

Quoted 34 lines

Hi Dmitry,

Quoted 31 lines · Dmitry Osipenko

27.02.2020 20:08, Dmitry Osipenko пишет:

Quoted 19 lines

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.

---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c +0 -0
index 8494c5f05a73..2011f64bfa3a 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 775

Quoted 8 lines
drivers/devfreq/devfreq.c +1 -1
@@ -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,

Quoted 5 lines
Quoted 2 lines

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 :)