Skip to content

Commit 45150c4

Browse files
olofjtorvalds
authored andcommitted
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>
1 parent ef9a61b commit 45150c4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/direct-io.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ static inline int dio_bio_reap(struct dio *dio, struct dio_submit *sdio)
544544
*/
545545
static int sb_init_dio_done_wq(struct super_block *sb)
546546
{
547+
struct workqueue_struct *old;
547548
struct workqueue_struct *wq = alloc_workqueue("dio/%s",
548549
WQ_MEM_RECLAIM, 0,
549550
sb->s_id);
@@ -552,9 +553,9 @@ static int sb_init_dio_done_wq(struct super_block *sb)
552553
/*
553554
* This has to be atomic as more DIOs can race to create the workqueue
554555
*/
555-
cmpxchg(&sb->s_dio_done_wq, NULL, wq);
556+
old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
556557
/* Someone created workqueue before us? Free ours... */
557-
if (wq != sb->s_dio_done_wq)
558+
if (old)
558559
destroy_workqueue(wq);
559560
return 0;
560561
}

0 commit comments

Comments
 (0)