Skip to content

Commit 033c88d

Browse files
committed
Merge tag 'thermal-5.20-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more thermal control updates from Rafael Wysocki: "These fix an error code path issue leading to a NULL pointer dereference, drop Kconfig dependencies that are not needed any more after recent changes, add CPU IDs for new chips to a driver and fix up the tmon utility. Specifics: - Fix NULL pointer dereference in the thermal sysfs interface that results from an error code path mishandling (Rafael Wysocki). - Drop COMPILE_TEST dependency that's not needed any more from two thermal Kconfig entries (Jean Delvare). - Make the Intel TCC cooling driver support Alder Lake-N and Raptor Lake-P (Sumeet Pawnikar). - Fix possible path truncations in the tmon utility (Florian Fainelli)" * tag 'thermal-5.20-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: tools/thermal: Fix possible path truncations thermal: Drop obsolete dependency on COMPILE_TEST thermal: sysfs: Fix cooling_device_stats_setup() error code path thermal: intel: Add TCC cooling support for Alder Lake-N and Raptor Lake-P
2 parents d5af75f + 7f0169c commit 033c88d

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

drivers/thermal/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ config THERMAL_EMULATION
221221

222222
config THERMAL_MMIO
223223
tristate "Generic Thermal MMIO driver"
224-
depends on OF || COMPILE_TEST
224+
depends on OF
225225
depends on HAS_IOMEM
226226
help
227227
This option enables the generic thermal MMIO driver that will use
@@ -496,7 +496,7 @@ config SPRD_THERMAL
496496

497497
config KHADAS_MCU_FAN_THERMAL
498498
tristate "Khadas MCU controller FAN cooling support"
499-
depends on OF || COMPILE_TEST
499+
depends on OF
500500
depends on MFD_KHADAS_MCU
501501
select MFD_CORE
502502
select REGMAP

drivers/thermal/intel/intel_tcc_cooling.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ static const struct x86_cpu_id tcc_ids[] __initconst = {
8181
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE, NULL),
8282
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE, NULL),
8383
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, NULL),
84+
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_N, NULL),
8485
X86_MATCH_INTEL_FAM6_MODEL(RAPTORLAKE, NULL),
86+
X86_MATCH_INTEL_FAM6_MODEL(RAPTORLAKE_P, NULL),
8587
{}
8688
};
8789

drivers/thermal/thermal_sysfs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,13 @@ static const struct attribute_group cooling_device_stats_attr_group = {
813813

814814
static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
815815
{
816+
const struct attribute_group *stats_attr_group = NULL;
816817
struct cooling_dev_stats *stats;
817818
unsigned long states;
818819
int var;
819820

820821
if (cdev->ops->get_max_state(cdev, &states))
821-
return;
822+
goto out;
822823

823824
states++; /* Total number of states is highest state + 1 */
824825

@@ -828,7 +829,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
828829

829830
stats = kzalloc(var, GFP_KERNEL);
830831
if (!stats)
831-
return;
832+
goto out;
832833

833834
stats->time_in_state = (ktime_t *)(stats + 1);
834835
stats->trans_table = (unsigned int *)(stats->time_in_state + states);
@@ -838,9 +839,12 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev)
838839

839840
spin_lock_init(&stats->lock);
840841

842+
stats_attr_group = &cooling_device_stats_attr_group;
843+
844+
out:
841845
/* Fill the empty slot left in cooling_device_attr_groups */
842846
var = ARRAY_SIZE(cooling_device_attr_groups) - 2;
843-
cooling_device_attr_groups[var] = &cooling_device_stats_attr_group;
847+
cooling_device_attr_groups[var] = stats_attr_group;
844848
}
845849

846850
static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev)

tools/thermal/tmon/sysfs.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <stdint.h>
1414
#include <dirent.h>
1515
#include <libintl.h>
16+
#include <limits.h>
1617
#include <ctype.h>
1718
#include <time.h>
1819
#include <syslog.h>
@@ -33,9 +34,9 @@ int sysfs_set_ulong(char *path, char *filename, unsigned long val)
3334
{
3435
FILE *fd;
3536
int ret = -1;
36-
char filepath[256];
37+
char filepath[PATH_MAX + 2]; /* NUL and '/' */
3738

38-
snprintf(filepath, 256, "%s/%s", path, filename);
39+
snprintf(filepath, sizeof(filepath), "%s/%s", path, filename);
3940

4041
fd = fopen(filepath, "w");
4142
if (!fd) {
@@ -57,9 +58,9 @@ static int sysfs_get_ulong(char *path, char *filename, unsigned long *p_ulong)
5758
{
5859
FILE *fd;
5960
int ret = -1;
60-
char filepath[256];
61+
char filepath[PATH_MAX + 2]; /* NUL and '/' */
6162

62-
snprintf(filepath, 256, "%s/%s", path, filename);
63+
snprintf(filepath, sizeof(filepath), "%s/%s", path, filename);
6364

6465
fd = fopen(filepath, "r");
6566
if (!fd) {
@@ -76,9 +77,9 @@ static int sysfs_get_string(char *path, char *filename, char *str)
7677
{
7778
FILE *fd;
7879
int ret = -1;
79-
char filepath[256];
80+
char filepath[PATH_MAX + 2]; /* NUL and '/' */
8081

81-
snprintf(filepath, 256, "%s/%s", path, filename);
82+
snprintf(filepath, sizeof(filepath), "%s/%s", path, filename);
8283

8384
fd = fopen(filepath, "r");
8485
if (!fd) {
@@ -199,8 +200,8 @@ static int find_tzone_cdev(struct dirent *nl, char *tz_name,
199200
{
200201
unsigned long trip_instance = 0;
201202
char cdev_name_linked[256];
202-
char cdev_name[256];
203-
char cdev_trip_name[256];
203+
char cdev_name[PATH_MAX];
204+
char cdev_trip_name[PATH_MAX];
204205
int cdev_id;
205206

206207
if (nl->d_type == DT_LNK) {
@@ -213,7 +214,8 @@ static int find_tzone_cdev(struct dirent *nl, char *tz_name,
213214
return -EINVAL;
214215
}
215216
/* find the link to real cooling device record binding */
216-
snprintf(cdev_name, 256, "%s/%s", tz_name, nl->d_name);
217+
snprintf(cdev_name, sizeof(cdev_name) - 2, "%s/%s",
218+
tz_name, nl->d_name);
217219
memset(cdev_name_linked, 0, sizeof(cdev_name_linked));
218220
if (readlink(cdev_name, cdev_name_linked,
219221
sizeof(cdev_name_linked) - 1) != -1) {
@@ -226,8 +228,8 @@ static int find_tzone_cdev(struct dirent *nl, char *tz_name,
226228
/* find the trip point in which the cdev is binded to
227229
* in this tzone
228230
*/
229-
snprintf(cdev_trip_name, 256, "%s%s", nl->d_name,
230-
"_trip_point");
231+
snprintf(cdev_trip_name, sizeof(cdev_trip_name) - 1,
232+
"%s%s", nl->d_name, "_trip_point");
231233
sysfs_get_ulong(tz_name, cdev_trip_name,
232234
&trip_instance);
233235
/* validate trip point range, e.g. trip could return -1

0 commit comments

Comments
 (0)