Re: [PATCH 01/14] bcache: fix error info in register_bcache()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/15/21 7:49 AM, Coly Li wrote:
> From: Chao Yu <yuchao0@xxxxxxxxxx>
> 
> 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@xxxxxxxxxx>
> Signed-off-by: Coly Li <colyli@xxxxxxx>
> ---
>  drivers/md/bcache/super.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index bea8c4429ae8..0a20ccf5a1db 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -2620,8 +2620,11 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>  	if (SB_IS_BDEV(sb)) {
>  		struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
>  
> -		if (!dc)
> +		if (!dc) {
> +			ret = -ENOMEM;
> +			err = "cannot allocate memory";
>  			goto out_put_sb_page;
> +		}
>  
>  		mutex_lock(&bch_register_lock);
>  		ret = register_bdev(sb, sb_disk, bdev, dc);
> @@ -2632,11 +2635,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>  	} else {
>  		struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
>  
> -		if (!ca)
> +		if (!ca) {
> +			ret = -ENOMEM;
> +			err = "cannot allocate memory";
>  			goto out_put_sb_page;
> +		}
>  
>  		/* blkdev_put() will be called in bch_cache_release() */
> -		if (register_cache(sb, sb_disk, bdev, ca) != 0)
> +		ret = register_cache(sb, sb_disk, bdev, ca);
> +		if (ret)
>  			goto out_free_sb;
>  	}
>  
> 
Reviewed-by: Hannes Reinecke <hare@xxxxxxx>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		           Kernel Storage Architect
hare@xxxxxxx			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux