Re: [PATCH] random: Use try_cmpxchg in _credit_init_bits

From: Jason A. Donenfeld
Date: Sat Jul 16 2022 - 14:29:20 EST


Hi Uros,

On Thu, Jul 14, 2022 at 08:28:22PM +0200, Uros Bizjak wrote:
> Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> _credit_init_bits. x86 CMPXCHG instruction returns success in ZF flag,
> so this change saves a compare after cmpxchg (and related move
> instruction in front of cmpxchg).
>
> Also, try_cmpxchg implicitly assigns old *ptr value to "old"
> when cmpxchg fails, enabling further code simplifications.
>
> No functional change intended.

Applied as:
https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git/commit/?id=6a66e096619e3a737297eb2f9f535a287af43a95

Thanks for the patch.

Jason