[PATCH 3.16 267/328] bcache: explicitly destroy mutex while exiting

From: Ben Hutchings
Date: Sun Dec 09 2018 - 17:01:29 EST

3.16.62-rc1 review patch. If anyone has any objections, please let me know.


From: Liang Chen <liangchen.linux@xxxxxxxxx>

commit 330a4db89d39a6b43f36da16824eaa7a7509d34d upstream.

mutex_destroy does nothing most of time, but it's better to call
it to make the code future proof and it also has some meaning
for like mutex debug.

As Coly pointed out in a previous review, bcache_exit() may not be
able to handle all the references properly if userspace registers
cache and backing devices right before bch_debug_init runs and
bch_debug_init failes later. So not exposing userspace interface
until everything is ready to avoid that issue.

Signed-off-by: Liang Chen <liangchen.linux@xxxxxxxxx>
Reviewed-by: Michael Lyle <mlyle@xxxxxxxx>
Reviewed-by: Coly Li <colyli@xxxxxxx>
Reviewed-by: Eric Wheeler <bcache@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
drivers/md/bcache/super.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2115,6 +2115,7 @@ static void bcache_exit(void)
if (bcache_major)
unregister_blkdev(bcache_major, "bcache");
+ mutex_destroy(&bch_register_lock);

static int __init bcache_init(void)
@@ -2133,14 +2134,15 @@ static int __init bcache_init(void)
bcache_major = register_blkdev(0, "bcache");
if (bcache_major < 0) {
+ mutex_destroy(&bch_register_lock);
return bcache_major;

if (!(bcache_wq = alloc_workqueue("bcache", WQ_MEM_RECLAIM, 0)) ||
!(bcache_kobj = kobject_create_and_add("bcache", fs_kobj)) ||
- sysfs_create_files(bcache_kobj, files) ||
bch_request_init() ||
- bch_debug_init(bcache_kobj))
+ bch_debug_init(bcache_kobj) ||
+ sysfs_create_files(bcache_kobj, files))
goto err;

return 0;