From 5ddd020b8bd0fb2fdcdc1f8c40513c656a690f80 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Mon, 23 Feb 2026 08:32:45 +0100 Subject: [PATCH 1/3] thermal: core: Replace sprintf() in thermal_bind_cdev_to_trip() Replace unbounded sprintf() with the safer snprintf(). While the current code works correctly, snprintf() is safer and follows secure coding best practices. No functional changes. Signed-off-by: Thorsten Blum Reviewed-by: Lukasz Luba [ rjw: Subject tweaks ] Link: https://patch.msgid.link/20260223073245.321298-2-thorsten.blum@linux.dev Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b7d706ed7ed9..479916b67f48 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -861,7 +861,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, goto free_mem; dev->id = result; - sprintf(dev->name, "cdev%d", dev->id); + snprintf(dev->name, sizeof(dev->name), "cdev%d", dev->id); result = sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); if (result) From 2dc1b0dd4bbfa2a27e5432300d1c18eb51c7efed Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Wed, 11 Mar 2026 17:42:14 +0100 Subject: [PATCH 2/3] thermal: sysfs: Use str_enabled_disabled() helper in mode_show() Replace hard-coded strings with the str_enabled_disabled() helper. This unifies the output and helps the linker with deduplication, which may result in a smaller binary. Signed-off-by: Thorsten Blum [ rjw: Subject and changelog tweaks ] Link: https://patch.msgid.link/20260311164212.405981-3-thorsten.blum@linux.dev Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_sysfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 46b3b2df935c..5eecae13f07d 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "thermal_core.h" @@ -56,10 +57,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) guard(thermal_zone)(tz); - if (tz->mode == THERMAL_DEVICE_ENABLED) - return sysfs_emit(buf, "enabled\n"); - - return sysfs_emit(buf, "disabled\n"); + return sysfs_emit(buf, "%s\n", + str_enabled_disabled(tz->mode == THERMAL_DEVICE_ENABLED)); } static ssize_t From 945471425a374e15a0d1a85b35913e1acdcd4a99 Mon Sep 17 00:00:00 2001 From: Anas Iqbal Date: Mon, 23 Mar 2026 09:40:18 +0000 Subject: [PATCH 3/3] thermal: devfreq_cooling: avoid unnecessary kfree of freq_table dfc->freq_table is only allocated in the non-EM path via devfreq_cooling_gen_tables(). In the EM path, it remains NULL. Avoid calling kfree() unnecessarily when freq_table was never allocated. This resolves a Smatch warning: calling kfree() when 'dfc->freq_table' is always NULL. Signed-off-by: Anas Iqbal Reviewed-by: Lukasz Luba Link: https://patch.msgid.link/20260323094018.2264-1-mohd.abd.6602@gmail.com Signed-off-by: Rafael J. Wysocki --- drivers/thermal/devfreq_cooling.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 597e86d16a4e..1c7dffc8d45f 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -472,7 +472,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, remove_qos_req: dev_pm_qos_remove_request(&dfc->req_max_freq); free_table: - kfree(dfc->freq_table); + if (!dfc->em_pd) + kfree(dfc->freq_table); free_dfc: kfree(dfc);