Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

direct-io: Use return from cmpxchg to decide of assignment happened

Not using the return value can in the generic case be racy, so it's
in general good practice to check the return value instead.

This also resolved the warning caused on ARM and other architectures:

fs/direct-io.c: In function 'sb_init_dio_done_wq':
fs/direct-io.c:557:2: warning: value computed is not used [-Wunused-value]

Signed-off-by: Olof Johansson <olof@lixom.net>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: H Peter Anvin <hpa@zytor.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Olof Johansson and committed by
Linus Torvalds
45150c43 ef9a61be

+3 -2
+3 -2
fs/direct-io.c
··· 544 544 */ 545 545 static int sb_init_dio_done_wq(struct super_block *sb) 546 546 { 547 + struct workqueue_struct *old; 547 548 struct workqueue_struct *wq = alloc_workqueue("dio/%s", 548 549 WQ_MEM_RECLAIM, 0, 549 550 sb->s_id); ··· 553 552 /* 554 553 * This has to be atomic as more DIOs can race to create the workqueue 555 554 */ 556 - cmpxchg(&sb->s_dio_done_wq, NULL, wq); 555 + old = cmpxchg(&sb->s_dio_done_wq, NULL, wq); 557 556 /* Someone created workqueue before us? Free ours... */ 558 - if (wq != sb->s_dio_done_wq) 557 + if (old) 559 558 destroy_workqueue(wq); 560 559 return 0; 561 560 }