Skip to content

Commit 1d97b8e

Browse files
tobluxrafaeljw
authored andcommitted
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>
1 parent 9ace475 commit 1d97b8e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/thermal/thermal_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,15 +1505,19 @@ thermal_zone_device_register_with_trips(const char *type,
15051505
const struct thermal_trip *trip = trips;
15061506
struct thermal_zone_device *tz;
15071507
struct thermal_trip_desc *td;
1508+
size_t type_len = 0;
15081509
int id;
15091510
int result;
15101511

1511-
if (!type || strlen(type) == 0) {
1512+
if (type)
1513+
type_len = strnlen(type, THERMAL_NAME_LENGTH);
1514+
1515+
if (type_len == 0) {
15121516
pr_err("No thermal zone type defined\n");
15131517
return ERR_PTR(-EINVAL);
15141518
}
15151519

1516-
if (strlen(type) >= THERMAL_NAME_LENGTH) {
1520+
if (type_len == THERMAL_NAME_LENGTH) {
15171521
pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
15181522
type, THERMAL_NAME_LENGTH);
15191523
return ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)