Skip to contentSkip to conversation

perf: fix cmpxchg warning in perf_event_amd.c

PATCH In review Jason Baron 2 participants 2 messages May 18, 2010 – May 19, 2010

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

PATCH 1/1 perf: fix cmpxchg warning in perf_event_amd.c

Hi,

I'm getting the following warnings:

In file included from arch/x86/kernel/cpu/perf_event.c:1343:
arch/x86/kernel/cpu/perf_event_amd.c: In function ‘amd_put_event_constraints’:
arch/x86/kernel/cpu/perf_event_amd.c:167: warning: value computed is not used

Since cmpxchg returns a value, we need to use it. We can use it to test if its equal to "event".

thanks,

-Jason

---
 arch/x86/kernel/cpu/perf_event_amd.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/perf_event_amd.c +1 -3
index 611df11..e13ce4a 100644
@@ -163,10 +163,8 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
 	 * when we come here
 	 */
 	for (i = 0; i < x86_pmu.num_counters; i++) {
-		if (nb->owners[i] == event) {
-			cmpxchg(nb->owners+i, event, NULL);
+		if (cmpxchg(nb->owners+i, event, NULL) == event)
 			break;
-		}
 	}
 }
 
Signature · 1 line
1.7.0.1
maintainer
#1 lore raw
Quoted 4 lines · Jason Baron

Hi,

I'm getting the following warnings:

Quoted 8 lines

In file included from arch/x86/kernel/cpu/perf_event.c:1343:
arch/x86/kernel/cpu/perf_event_amd.c: In function ‘amd_put_event_constraints’:
arch/x86/kernel/cpu/perf_event_amd.c:167: warning: value computed is not used

Since cmpxchg returns a value, we need to use it. We can use it to test if its equal to "event".

Should we:

a) add a WARN_ONCE() there and make use of the return value (it should
never happen)

or

b) replace the lot with: nb->owners[i] = NULL; which should I _think_
work.

Quoted 21 lines
---
 arch/x86/kernel/cpu/perf_event_amd.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/perf_event_amd.c +1 -3
index 611df11..e13ce4a 100644
@@ -163,10 +163,8 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
 	 * when we come here
 	 */
 	for (i = 0; i < x86_pmu.num_counters; i++) {
-		if (nb->owners[i] == event) {
-			cmpxchg(nb->owners+i, event, NULL);
+		if (cmpxchg(nb->owners+i, event, NULL) == event)
 			break;
-		}
 	}
 }