]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: Use try_cmpxchg() in sb_init_done_wq()
authorUros Bizjak <ubizjak@gmail.com>
Mon, 11 Aug 2025 13:23:03 +0000 (15:23 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 25 Aug 2025 12:09:25 +0000 (14:09 +0200)
Use !try_cmpxchg() instead of cmpxchg(*ptr, old, new) != old.

The x86 CMPXCHG instruction returns success in the ZF flag,
so this change saves a compare after CMPXCHG.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Link: https://lore.kernel.org/20250811132326.620521-1-ubizjak@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/super.c

index 7f876f32343ad47fc082b72b2c521bcaaa2f6873..e9171801770182d397987f978b12b4b80372f3cf 100644 (file)
@@ -2318,13 +2318,15 @@ int sb_init_dio_done_wq(struct super_block *sb)
                                                      sb->s_id);
        if (!wq)
                return -ENOMEM;
+
+       old = NULL;
        /*
         * This has to be atomic as more DIOs can race to create the workqueue
         */
-       old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
-       /* Someone created workqueue before us? Free ours... */
-       if (old)
+       if (!try_cmpxchg(&sb->s_dio_done_wq, &old, wq)) {
+               /* Someone created workqueue before us? Free ours... */
                destroy_workqueue(wq);
+       }
        return 0;
 }
 EXPORT_SYMBOL_GPL(sb_init_dio_done_wq);