linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update
@ 2022-07-13 15:19 Uros Bizjak
  2022-07-14  8:49 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2022-07-13 15:19 UTC (permalink / raw)
  To: alsa-devel, linux-kernel; +Cc: Uros Bizjak, Takashi Iwai

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.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/endpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index f9c921683948..0d7b73bf7945 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -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);
 }
 
 /**
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update
  2022-07-13 15:19 [PATCH] ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update Uros Bizjak
@ 2022-07-14  8:49 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2022-07-14  8:49 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: alsa-devel, linux-kernel

On Wed, 13 Jul 2022 17:19:46 +0200,
Uros Bizjak wrote:
> 
> 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.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Takashi Iwai <tiwai@suse.de>

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-14  8:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 15:19 [PATCH] ALSA: usb-audio: Use atomic_try_cmpxchg in ep_state_update Uros Bizjak
2022-07-14  8:49 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).