* [PATCH] thermal: core: Use strnlen in thermal_zone_device_register_with_trips
@ 2025-12-15 12:16 Thorsten Blum
2025-12-16 12:18 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-12-15 12:16 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: Thorsten Blum, linux-pm, linux-kernel
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>
---
drivers/thermal/thermal_core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 17ca5c082643..63eb35b449c6 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1505,15 +1505,17 @@ 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;
int id;
int result;
- if (!type || strlen(type) == 0) {
+ type_len = type ? strnlen(type, THERMAL_NAME_LENGTH) : 0;
+ 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@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] thermal: core: Use strnlen in thermal_zone_device_register_with_trips
2025-12-15 12:16 [PATCH] thermal: core: Use strnlen in thermal_zone_device_register_with_trips Thorsten Blum
@ 2025-12-16 12:18 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-12-16 12:18 UTC (permalink / raw)
To: Thorsten Blum
Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
linux-pm, linux-kernel
On Mon, Dec 15, 2025 at 1:16 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> 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>
> ---
> drivers/thermal/thermal_core.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 17ca5c082643..63eb35b449c6 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1505,15 +1505,17 @@ 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;
size_t type_len = 0;
> int id;
> int result;
>
> - if (!type || strlen(type) == 0) {
> + type_len = type ? strnlen(type, THERMAL_NAME_LENGTH) : 0;
if (type)
type_len = strnlen(type, THERMAL_NAME_LENGTH);
Pretty please.
> + 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);
> --
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-16 12:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 12:16 [PATCH] thermal: core: Use strnlen in thermal_zone_device_register_with_trips Thorsten Blum
2025-12-16 12:18 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox