thermal: sysfs: switch to use scnprintf() to suppress truncation warning

Switch the sysfs code to use scnprintf() to avoid warnings about potential
truncation of the names of the sysfs attributes. We can't increase the buffer
size because the size is the part of an ABI for some reason. Note, with
the current size of buffer the affected attributes have a room for up to
1000 names, which ought to be enough for all cases. There is no functional
change, as the same limitation was implied before.

Fixes: c56f5c0342 ("Thermal: Make Thermal trip points writeable")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/20260817103324.1020212-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Andy Shevchenko
2026-09-04 15:49:46 +02:00
committed by Rafael J. Wysocki
parent cee9395acd
commit 5ad0af4f43
+6 -6
View File
@@ -400,8 +400,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
struct thermal_trip_attrs *trip_attrs = &td->trip_attrs;
/* create trip type attribute */
snprintf(trip_attrs->type.name, THERMAL_NAME_LENGTH,
"trip_point_%d_type", i);
scnprintf(trip_attrs->type.name, sizeof(trip_attrs->type.name),
"trip_point_%d_type", i);
sysfs_attr_init(&trip_attrs->type.attr.attr);
trip_attrs->type.attr.attr.name = trip_attrs->type.name;
@@ -410,8 +410,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
attrs[i] = &trip_attrs->type.attr.attr;
/* create trip temp attribute */
snprintf(trip_attrs->temp.name, THERMAL_NAME_LENGTH,
"trip_point_%d_temp", i);
scnprintf(trip_attrs->temp.name, sizeof(trip_attrs->temp.name),
"trip_point_%d_temp", i);
sysfs_attr_init(&trip_attrs->temp.attr.attr);
trip_attrs->temp.attr.attr.name = trip_attrs->temp.name;
@@ -423,8 +423,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
}
attrs[i + tz->num_trips] = &trip_attrs->temp.attr.attr;
snprintf(trip_attrs->hyst.name, THERMAL_NAME_LENGTH,
"trip_point_%d_hyst", i);
scnprintf(trip_attrs->hyst.name, sizeof(trip_attrs->hyst.name),
"trip_point_%d_hyst", i);
sysfs_attr_init(&trip_attrs->hyst.attr.attr);
trip_attrs->hyst.attr.attr.name = trip_attrs->hyst.name;