linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcache: fix error info in register_bcache()
@ 2021-05-19 13:28 Chao Yu
  2021-05-19 16:43 ` Coly Li
  0 siblings, 1 reply; 2+ messages in thread
From: Chao Yu @ 2021-05-19 13:28 UTC (permalink / raw)
  To: colyli; +Cc: linux-bcache, linux-kernel, Chao Yu

From: Chao Yu <yuchao0@huawei.com>

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>
---
 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;
 	}
 
-- 
2.22.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bcache: fix error info in register_bcache()
  2021-05-19 13:28 [PATCH] bcache: fix error info in register_bcache() Chao Yu
@ 2021-05-19 16:43 ` Coly Li
  0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2021-05-19 16:43 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-bcache, linux-kernel, Chao Yu

On 5/19/21 9:28 PM, Chao Yu wrote:
> From: Chao Yu <yuchao0@huawei.com>
> 
> 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>

Will add it to my test queue.

Thanks.

Coly Li


> ---
>  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;
>  	}
>  
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-19 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 13:28 [PATCH] bcache: fix error info in register_bcache() Chao Yu
2021-05-19 16:43 ` Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).