summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-12-16 14:09:44 +0100
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-01-07 21:27:07 +0100
commit1d97b8e3bfbb4fec99054cb5c413652a0ccfdeec (patch)
treea4d28808b2c9948890c498f7a479c31a5e4c1482
parent9ace4753a5202b02191d54e9fdf7f9e3d02b85eb (diff)
downloadlinux-1d97b8e3bfbb4fec99054cb5c413652a0ccfdeec.tar.gz
linux-1d97b8e3bfbb4fec99054cb5c413652a0ccfdeec.zip
thermal: core: Use strnlen() in thermal_zone_device_register_with_trips()
Replace strlen() with the safer strnlen() and calculate the length of the thermal zone name 'type' only once. No functional changes. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> [ rjw: Subject edits ] Link: https://patch.msgid.link/20251216130943.40180-2-thorsten.blum@linux.dev Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/thermal/thermal_core.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 89758c9934ec..dc9f7416f7ff 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1505,15 +1505,19 @@ thermal_zone_device_register_with_trips(const char *type,
const struct thermal_trip *trip = trips;
struct thermal_zone_device *tz;
struct thermal_trip_desc *td;
+ size_t type_len = 0;
int id;
int result;
- if (!type || strlen(type) == 0) {
+ if (type)
+ type_len = strnlen(type, THERMAL_NAME_LENGTH);
+
+ if (type_len == 0) {
pr_err("No thermal zone type defined\n");
return ERR_PTR(-EINVAL);
}
- if (strlen(type) >= THERMAL_NAME_LENGTH) {
+ if (type_len == THERMAL_NAME_LENGTH) {
pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
type, THERMAL_NAME_LENGTH);
return ERR_PTR(-EINVAL);