Skip to content

Commit fe6a6de

Browse files
spandruvadadlezcano
authored andcommitted
thermal/drivers/int340x/processor_thermal: Fix tcc setting
The following fixes are done for tcc sysfs interface: - TCC is 6 bits only from bit 29-24 - TCC of 0 is valid - When BIT(31) is set, this register is read only - Check for invalid tcc value - Error for negative values Fixes: fdf4f2f ("drivers: thermal: processor_thermal_device: Export sysfs interface for TCC offset") Signed-off-by: Srinivas Pandruvada <[email protected]> Cc: [email protected] Acked-by: Zhang Rui <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ad079d9 commit fe6a6de

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,27 @@ static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
7878
if (err)
7979
return err;
8080

81-
val = (val >> 24) & 0xff;
81+
val = (val >> 24) & 0x3f;
8282
return sprintf(buf, "%d\n", (int)val);
8383
}
8484

85-
static int tcc_offset_update(int tcc)
85+
static int tcc_offset_update(unsigned int tcc)
8686
{
8787
u64 val;
8888
int err;
8989

90-
if (!tcc)
90+
if (tcc > 63)
9191
return -EINVAL;
9292

9393
err = rdmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, &val);
9494
if (err)
9595
return err;
9696

97-
val &= ~GENMASK_ULL(31, 24);
98-
val |= (tcc & 0xff) << 24;
97+
if (val & BIT(31))
98+
return -EPERM;
99+
100+
val &= ~GENMASK_ULL(29, 24);
101+
val |= (tcc & 0x3f) << 24;
99102

100103
err = wrmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, val);
101104
if (err)
@@ -104,14 +107,15 @@ static int tcc_offset_update(int tcc)
104107
return 0;
105108
}
106109

107-
static int tcc_offset_save;
110+
static unsigned int tcc_offset_save;
108111

109112
static ssize_t tcc_offset_degree_celsius_store(struct device *dev,
110113
struct device_attribute *attr, const char *buf,
111114
size_t count)
112115
{
116+
unsigned int tcc;
113117
u64 val;
114-
int tcc, err;
118+
int err;
115119

116120
err = rdmsrl_safe(MSR_PLATFORM_INFO, &val);
117121
if (err)
@@ -120,7 +124,7 @@ static ssize_t tcc_offset_degree_celsius_store(struct device *dev,
120124
if (!(val & BIT(30)))
121125
return -EACCES;
122126

123-
if (kstrtoint(buf, 0, &tcc))
127+
if (kstrtouint(buf, 0, &tcc))
124128
return -EINVAL;
125129

126130
err = tcc_offset_update(tcc);

0 commit comments

Comments
 (0)