Skip to content

Commit

Permalink
dm crypt: fix async inc_pending
Browse files Browse the repository at this point in the history
The pending reference count must be incremented *before* the async work is
queued to another thread, not after.  Otherwise there's a race if the
work completes and decrements the reference count before it gets incremented.

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Milan Broz authored and Alasdair G Kergon committed Oct 10, 2008
1 parent 6c031f4 commit 4e59409
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/md/dm-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,16 +719,15 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)

remaining -= clone->bi_size;

crypt_inc_pending(io);
r = crypt_convert(cc, &io->ctx);

if (atomic_dec_and_test(&io->ctx.pending)) {
/* processed, no running async crypto */
crypt_inc_pending(io);
kcryptd_crypt_write_io_submit(io, r, 0);
if (unlikely(r < 0))
break;
} else
crypt_inc_pending(io);
}

/* out of memory -> run queues */
if (unlikely(remaining)) {
Expand Down

0 comments on commit 4e59409

Please sign in to comment.