Skip to contentSkip to conversation

intel_pstate: Fix type mismatch warning

PATCH New Rafael J. Wysocki 2 participants 5 messages Oct 15, 2013 – Oct 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 intel_pstate: Fix type mismatch warning

From: Rafael J. Wysocki <[email protected]>

The expression in line 398 of intel_pstate.c causes the following warning to be emitted:

drivers/cpufreq/intel_pstate.c:398:3: warning: left shift count >= width of type

which is due to the fact that the pstate variable is of type int. Fix that by using a helper unsigned long variable and simplify the code slightly.

---
 drivers/cpufreq/intel_pstate.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -3
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(str
 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
 {
 	int max_perf, min_perf;
+	unsigned long val;
 
 	intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
 
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(stru
 	trace_cpu_frequency(pstate * 100000, cpu->cpu);
 
 	cpu->pstate.current_pstate = pstate;
+	val = pstate << 8;
 	if (limits.no_turbo)
-		wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8));
-	else
-		wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
+		val |= BIT(32);
 
+	wrmsrl(MSR_IA32_PERF_CTL, val);
 }
 
 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
#1 lore raw

PATCH 1/1 intel_pstate: Fix type mismatch warning

From: Rafael J. Wysocki <[email protected]>

The expression in line 398 of intel_pstate.c causes the following warning to be emitted:

drivers/cpufreq/intel_pstate.c:398:3: warning: left shift count >= width of type

which happens because unsigned long is 32-bit on some architectures. Fix that by using a helper u64 variable and simplify the code slightly.

---
 drivers/cpufreq/intel_pstate.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -3
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(str
 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
 {
 	int max_perf, min_perf;
+	u64 val;
 
 	intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
 
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(stru
 	trace_cpu_frequency(pstate * 100000, cpu->cpu);
 
 	cpu->pstate.current_pstate = pstate;
+	val = pstate << 8;
 	if (limits.no_turbo)
-		wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8));
-	else
-		wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
+		val |= (u64)1 << 32;
 
+	wrmsrl(MSR_IA32_PERF_CTL, val);
 }
 
 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
#2 lore raw
Quoted 35 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The expression in line 398 of intel_pstate.c causes the following warning to be emitted:

drivers/cpufreq/intel_pstate.c:398:3: warning: left shift count >= width of type

which happens because unsigned long is 32-bit on some architectures. Fix that by using a helper u64 variable and simplify the code slightly.

---
  drivers/cpufreq/intel_pstate.c |    7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================

drivers/cpufreq/intel_pstate.c +2 -0
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(str
  static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
  {
  	int max_perf, min_perf;
+	u64 val;
 
  	intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
 
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(stru
  	trace_cpu_frequency(pstate * 100000, cpu->cpu);
 
  	cpu->pstate.current_pstate = pstate;
+	val = pstate << 8;

drivers/cpufreq/intel_pstate.c static void intel_pstate_set_pstate(stru · line 405

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +2 -3
  	if (limits.no_turbo)
-		wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8));
-	else
-		wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
+		val |= (u64)1 << 32;
 
+	wrmsrl(MSR_IA32_PERF_CTL, val);
  }
 
  static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)

Tested with this change.

Thanks,
Srinivas

#3 lore raw
Quoted 40 lines · Srinivas Pandruvada
Quoted 39 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The expression in line 398 of intel_pstate.c causes the following warning to be emitted:

drivers/cpufreq/intel_pstate.c:398:3: warning: left shift count >= width of type

which happens because unsigned long is 32-bit on some architectures. Fix that by using a helper u64 variable and simplify the code slightly.

---
  drivers/cpufreq/intel_pstate.c |    7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================

drivers/cpufreq/intel_pstate.c +3 -3
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(str
  static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
  {
  	int max_perf, min_perf;
+	u64 val;
 
  	intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
 
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(stru
  	trace_cpu_frequency(pstate * 100000, cpu->cpu);
 
  	cpu->pstate.current_pstate = pstate;
+	val = pstate << 8;
  	if (limits.no_turbo)
-		wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8));
-	else
-		wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
+		val |= (u64)1 << 32;
 
Quoted 7 lines

drivers/cpufreq/intel_pstate.c static void intel_pstate_set_pstate(stru · line 405

Quoted 6 lines
drivers/cpufreq/intel_pstate.c +1 -0
+	wrmsrl(MSR_IA32_PERF_CTL, val);
  }
 
  static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)

Tested with this change.

Cool, thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#4 lore raw

PATCH RESEND 1/1 intel_pstate: Fix type mismatch warning

In reply to Srinivas Pandruvada

From: Rafael J. Wysocki <[email protected]>

The expression in line 398 of intel_pstate.c causes the following warning to be emitted:

drivers/cpufreq/intel_pstate.c:398:3: warning: left shift count >= width of type

which happens because unsigned long is 32-bit on some architectures.

Fix that by using a helper u64 variable and simplify the code slightly.

---
 drivers/cpufreq/intel_pstate.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -3
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
@@ -383,6 +383,7 @@ static void intel_pstate_get_min_max(str
 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
 {
 	int max_perf, min_perf;
+	u64 val;
 
 	intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
 
@@ -394,11 +395,11 @@ static void intel_pstate_set_pstate(stru
 	trace_cpu_frequency(pstate * 100000, cpu->cpu);
 
 	cpu->pstate.current_pstate = pstate;
+	val = pstate << 8;
 	if (limits.no_turbo)
-		wrmsrl(MSR_IA32_PERF_CTL, BIT(32) | (pstate << 8));
-	else
-		wrmsrl(MSR_IA32_PERF_CTL, pstate << 8);
+		val |= (u64)1 << 32;
 
+	wrmsrl(MSR_IA32_PERF_CTL, val);
 }
 
 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)