[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251216130943.40180-2-thorsten.blum@linux.dev>
Date: Tue, 16 Dec 2025 14:09:44 +0100
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: "Rafael J. Wysocki" <rafael@...nel.org>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Zhang Rui <rui.zhang@...el.com>,
Lukasz Luba <lukasz.luba@....com>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] 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@...ux.dev>
---
Changes in v2:
- Format the code differently (Rafael)
- Link to v1: https://lore.kernel.org/lkml/20251215121633.375193-1-thorsten.blum@linux.dev/
---
drivers/thermal/thermal_core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 17ca5c082643..90e7edf16a52 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);
--
Thorsten Blum <thorsten.blum@...ux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Powered by blists - more mailing lists