Skip to contentSkip to conversation

thermal: sysfs: Replace snprintf with strscpy in policy_store

PATCH Applied Thorsten Blum 2 participants 2 messages Jan 12 – Jan 15 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: sysfs: Replace snprintf with strscpy in policy_store

There is no need to use snprintf with a format specifier to copy 'buf' to 'name'; use strscpy() directly instead.

---
 drivers/thermal/thermal_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +1 -1
index d80612506a33..e9580ddf4882 100644
@@ -199,7 +199,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
 	char name[THERMAL_NAME_LENGTH];
 	int ret;
 
-	snprintf(name, sizeof(name), "%s", buf);
+	strscpy(name, buf);
 
 	ret = thermal_zone_device_set_policy(tz, name);
 	if (!ret)
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer Applied
#1 lore raw
Quoted 14 lines · Thorsten Blum

There is no need to use snprintf with a format specifier to copy 'buf' to 'name'; use strscpy() directly instead.

---
 drivers/thermal/thermal_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +0 -0
index d80612506a33..e9580ddf4882 100644

drivers/thermal/thermal_sysfs.c policy_store(struct device *dev, struct device_attribute *attr,

Quoted 9 lines
drivers/thermal/thermal_sysfs.c +1 -2
@@ -199,7 +199,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
        char name[THERMAL_NAME_LENGTH];
        int ret;
 
-       snprintf(name, sizeof(name), "%s", buf);
+       strscpy(name, buf);
 
        ret = thermal_zone_device_set_policy(tz, name);
        if (!ret)
--

Applied as 6.20 material, thanks!