bcache: Fix a dumb race
authorKent Overstreet <kmo@daterainc.com>
Thu, 11 Jul 2013 01:04:21 +0000 (18:04 -0700)
committerKent Overstreet <kmo@daterainc.com>
Fri, 12 Jul 2013 07:22:33 +0000 (00:22 -0700)
commit6aa8f1a6ca41c49721d2de4e048d3da8d06411f9
tree2d7be747ae6dea479779fd8f993ef74744c27e6a
parent8e51e414a3c6d92ef2cc41720c67342a8e2c0bf7
bcache: Fix a dumb race

In the far-too-complicated closure code - closures can have destructors,
for probably dubious reasons; they get run after the closure is no
longer waiting on anything but before dropping the parent ref, intended
just for freeing whatever memory the closure is embedded in.

Trouble is, when remaining goes to 0 and we've got nothing more to run -
we also have to unlock the closure, setting remaining to -1. If there's
a destructor, that unlock isn't doing anything - nobody could be trying
to lock it if we're about to free it - but if the unlock _is needed...
that check for a destructor was racy. Argh.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
drivers/md/bcache/closure.c