Skip to content

Commit a1d1d8f

Browse files
dhananjay-AMDsuperm1
authored andcommitted
cpufreq/amd-pstate: Fix the clamping of perf values
The clamping in freq_to_perf() is broken right now, as we first typecast (read wraparound) the overflowing value into a u8 and then clamp it down. So, use a u32 to store the >255 value in certain edge cases and then clamp it down into a u8. Also, use a "explicit typecast + clamp" instead of just a "clamp_t" as the latter typecasts first and then clamps between the limits, which defeats our purpose. Fixes: 620136c ("cpufreq/amd-pstate: Modularize perf<->freq conversion") Signed-off-by: Dhananjay Ugwekar <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mario Limonciello <[email protected]>
1 parent 3e93edc commit a1d1d8f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ static struct quirk_entry quirk_amd_7k62 = {
144144

145145
static inline u8 freq_to_perf(struct amd_cpudata *cpudata, unsigned int freq_val)
146146
{
147-
u8 perf_val = DIV_ROUND_UP_ULL((u64)freq_val * cpudata->nominal_perf,
147+
u32 perf_val = DIV_ROUND_UP_ULL((u64)freq_val * cpudata->nominal_perf,
148148
cpudata->nominal_freq);
149149

150-
return clamp_t(u8, perf_val, cpudata->lowest_perf, cpudata->highest_perf);
150+
return (u8)clamp(perf_val, cpudata->lowest_perf, cpudata->highest_perf);
151151
}
152152

153153
static inline u32 perf_to_freq(struct amd_cpudata *cpudata, u8 perf_val)

0 commit comments

Comments
 (0)