Skip to contentSkip to conversation

ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update

PATCH Applied Uros Bizjak 2 participants 2 messages Jul 13, 2022 – Jul 14, 2022 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update

Use atomic_try_cmpxchg instead of atomic_cmpxchg (*ptr, old, new) == old in ep_state_update. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg).

No functional change intended.

---
 sound/usb/endpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/endpoint.c +1 -1
index f9c921683948..0d7b73bf7945 100644
@@ -133,7 +133,7 @@ static inline bool ep_state_running(struct snd_usb_endpoint *ep)
 
 static inline bool ep_state_update(struct snd_usb_endpoint *ep, int old, int new)
 {
-	return atomic_cmpxchg(&ep->state, old, new) == old;
+	return atomic_try_cmpxchg(&ep->state, &old, new);
 }
 
 /**
Signature · 1 line
2.35.3
Applied
#1 lore raw
Quoted 10 lines · Uros Bizjak

Use atomic_try_cmpxchg instead of atomic_cmpxchg (*ptr, old, new) == old in ep_state_update. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg).

No functional change intended.

Thanks, applied.

Takashi