Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bcache: add error handling support for add_disk()

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

This driver doesn't do any unwinding with blk_cleanup_disk()
even on errors after add_disk() and so we follow that
tradition.

Acked-by: Coly Li <colyli@suse.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20211015233028.2167651-5-mcgrof@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Luis Chamberlain and committed by
Jens Axboe
2961c3bb e7089f65

+12 -5
+12 -5
drivers/md/bcache/super.c
··· 1080 1080 closure_sync(&cl); 1081 1081 } 1082 1082 1083 - add_disk(d->disk); 1083 + ret = add_disk(d->disk); 1084 + if (ret) 1085 + goto out; 1084 1086 bd_link_disk_holder(dc->bdev, dc->disk.disk); 1085 1087 /* 1086 1088 * won't show up in the uevent file, use udevadm monitor -e instead ··· 1528 1526 1529 1527 static int flash_dev_run(struct cache_set *c, struct uuid_entry *u) 1530 1528 { 1529 + int err = -ENOMEM; 1531 1530 struct bcache_device *d = kzalloc(sizeof(struct bcache_device), 1532 1531 GFP_KERNEL); 1533 1532 if (!d) 1534 - return -ENOMEM; 1533 + goto err_ret; 1535 1534 1536 1535 closure_init(&d->cl, NULL); 1537 1536 set_closure_fn(&d->cl, flash_dev_flush, system_wq); ··· 1546 1543 bcache_device_attach(d, c, u - c->uuids); 1547 1544 bch_sectors_dirty_init(d); 1548 1545 bch_flash_dev_request_init(d); 1549 - add_disk(d->disk); 1546 + err = add_disk(d->disk); 1547 + if (err) 1548 + goto err; 1550 1549 1551 - if (kobject_add(&d->kobj, &disk_to_dev(d->disk)->kobj, "bcache")) 1550 + err = kobject_add(&d->kobj, &disk_to_dev(d->disk)->kobj, "bcache"); 1551 + if (err) 1552 1552 goto err; 1553 1553 1554 1554 bcache_device_link(d, c, "volume"); ··· 1565 1559 return 0; 1566 1560 err: 1567 1561 kobject_put(&d->kobj); 1568 - return -ENOMEM; 1562 + err_ret: 1563 + return err; 1569 1564 } 1570 1565 1571 1566 static int flash_devs_run(struct cache_set *c)