Skip to content

Commit d55f7cb

Browse files
chaseyuaxboe
authored andcommitted
bcache: fix error info in register_bcache()
In register_bcache(), there are several cases we didn't set correct error info (return value and/or error message): - if kzalloc() fails, it needs to return ENOMEM and print "cannot allocate memory"; - if register_cache() fails, it's better to propagate its return value rather than using default EINVAL. Signed-off-by: Chao Yu <yuchao0@huawei.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Coly Li <colyli@suse.de> Link: https://lore.kernel.org/r/20211020143812.6403-4-colyli@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0a2b3e3 commit d55f7cb

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎drivers/md/bcache/super.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,8 +2617,11 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
26172617
if (SB_IS_BDEV(sb)) {
26182618
struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
26192619

2620-
if (!dc)
2620+
if (!dc) {
2621+
ret = -ENOMEM;
2622+
err = "cannot allocate memory";
26212623
goto out_put_sb_page;
2624+
}
26222625

26232626
mutex_lock(&bch_register_lock);
26242627
ret = register_bdev(sb, sb_disk, bdev, dc);
@@ -2629,11 +2632,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
26292632
} else {
26302633
struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
26312634

2632-
if (!ca)
2635+
if (!ca) {
2636+
ret = -ENOMEM;
2637+
err = "cannot allocate memory";
26332638
goto out_put_sb_page;
2639+
}
26342640

26352641
/* blkdev_put() will be called in bch_cache_release() */
2636-
if (register_cache(sb, sb_disk, bdev, ca) != 0)
2642+
ret = register_cache(sb, sb_disk, bdev, ca);
2643+
if (ret)
26372644
goto out_free_sb;
26382645
}
26392646

0 commit comments

Comments
 (0)