Skip to content

Commit

Permalink
direct-io: Use return from cmpxchg to decide of assignment happened
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Olof Johansson authored and Linus Torvalds committed Sep 9, 2013
1 parent ef9a61b commit 45150c4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ static inline int dio_bio_reap(struct dio *dio, struct dio_submit *sdio)
*/
static int sb_init_dio_done_wq(struct super_block *sb)
{
struct workqueue_struct *old;
struct workqueue_struct *wq = alloc_workqueue("dio/%s",
WQ_MEM_RECLAIM, 0,
sb->s_id);
Expand All @@ -552,9 +553,9 @@ static int sb_init_dio_done_wq(struct super_block *sb)
/*
* This has to be atomic as more DIOs can race to create the workqueue
*/
cmpxchg(&sb->s_dio_done_wq, NULL, wq);
old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
/* Someone created workqueue before us? Free ours... */
if (wq != sb->s_dio_done_wq)
if (old)
destroy_workqueue(wq);
return 0;
}
Expand Down

0 comments on commit 45150c4

Please sign in to comment.