From: ZouMingzhe <mingzhe.zou@xxxxxxxxxxxx> handle error when call bch_sectors_dirty_init() function Signed-off-by: mingzhe <mingzhe.zou@xxxxxxxxxxxx> --- drivers/md/bcache/super.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index ba3909bb6bea..9dcffeb4c182 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1298,21 +1298,17 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, bch_writeback_queue(dc); } - bch_sectors_dirty_init(&dc->disk); + ret = bch_sectors_dirty_init(&dc->disk); + if (ret) { + pr_err("Fails in sectors dirty init for %s\n", + dc->disk.disk->disk_name); + goto err; + } ret = bch_cached_dev_run(dc); if (ret && (ret != -EBUSY)) { - up_write(&dc->writeback_lock); - /* - * bch_register_lock is held, bcache_device_stop() is not - * able to be directly called. The kthread and kworker - * created previously in bch_cached_dev_writeback_start() - * have to be stopped manually here. - */ - kthread_stop(dc->writeback_thread); - cancel_writeback_rate_update_dwork(dc); pr_err("Couldn't run cached device %pg\n", dc->bdev); - return ret; + goto err; } bcache_device_link(&dc->disk, c, "bdev"); @@ -1332,6 +1328,18 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, dc->disk.disk->disk_name, dc->disk.c->set_uuid); return 0; + +err: + up_write(&dc->writeback_lock); + /* + * bch_register_lock is held, bcache_device_stop() is not + * able to be directly called. The kthread and kworker + * created previously in bch_cached_dev_writeback_start() + * have to be stopped manually here. + */ + kthread_stop(dc->writeback_thread); + cancel_writeback_rate_update_dwork(dc); + return ret; } /* when dc->disk.kobj released */ @@ -1540,7 +1548,9 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u) goto err; bcache_device_attach(d, c, u - c->uuids); - bch_sectors_dirty_init(d); + err = bch_sectors_dirty_init(d); + if (err) + goto err; bch_flash_dev_request_init(d); err = add_disk(d->disk); if (err) -- 2.17.1