bcache: register_bcache(): call blkdev_put() when cache_alloc() fails
authorEric Wheeler <git@linux.ewheeler.net>
Fri, 17 Jun 2016 22:01:54 +0000 (15:01 -0700)
committerSasha Levin <alexander.levin@verizon.com>
Wed, 31 Aug 2016 23:21:09 +0000 (19:21 -0400)
commit220360d6ac0e1ef0cf364028c26f44ac99c306c4
treef1d4706ca5fa41c52a2e9c0cdfee6c64dc352693
parent35b8f91bf61afc5764e739e718651afba580f9e8
bcache: register_bcache(): call blkdev_put() when cache_alloc() fails

[ Upstream commit d9dc1702b297ec4a6bb9c0326a70641b322ba886 ]

register_cache() is supposed to return an error string on error so that
register_bcache() will will blkdev_put and cleanup other user counters,
but it does not set 'char *err' when cache_alloc() fails (eg, due to
memory pressure) and thus register_bcache() performs no cleanup.

register_bcache() <----------\  <- no jump to err_close, no blkdev_put()
   |                         |
   +->register_cache()       |  <- fails to set char *err
         |                   |
         +->cache_alloc() ---/  <- returns error

This patch sets `char *err` for this failure case so that register_cache()
will cause register_bcache() to correctly jump to err_close and do
cleanup.  This was tested under OOM conditions that triggered the bug.

Signed-off-by: Eric Wheeler <bcache@linux.ewheeler.net>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
drivers/md/bcache/super.c