diff mbox series

[next] btrfs: fix check for memory allocation failure of ret->path

Message ID 20200421124703.149466-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show
Series [next] btrfs: fix check for memory allocation failure of ret->path | expand

Commit Message

Colin King April 21, 2020, 12:47 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently the memory allocation failure check for ret->path is checking
that ret is null rather than ret->path.  Fix this by checking ret->path
instead.

Addresses-Coverity: ("Dereference null return")
Fixes: bd8bdc532152 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/btrfs/backref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Qu Wenruo April 21, 2020, 12:48 p.m. UTC | #1
On 2020/4/21 下午8:47, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the memory allocation failure check for ret->path is checking
> that ret is null rather than ret->path.  Fix this by checking ret->path
> instead.
> 
> Addresses-Coverity: ("Dereference null return")
> Fixes: bd8bdc532152 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

My bad.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>  fs/btrfs/backref.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index 60a69f7c0b36..78e6c9a64212 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -2307,7 +2307,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(
>  		return NULL;
>  
>  	ret->path = btrfs_alloc_path();
> -	if (!ret) {
> +	if (!ret->path) {
>  		kfree(ret);
>  		return NULL;
>  	}
>
David Sterba April 27, 2020, 3:18 p.m. UTC | #2
On Tue, Apr 21, 2020 at 01:47:03PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the memory allocation failure check for ret->path is checking
> that ret is null rather than ret->path.  Fix this by checking ret->path
> instead.
> 
> Addresses-Coverity: ("Dereference null return")
> Fixes: bd8bdc532152 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")

As this is still in development branch, fixup folded in. Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 60a69f7c0b36..78e6c9a64212 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2307,7 +2307,7 @@  struct btrfs_backref_iter *btrfs_backref_iter_alloc(
 		return NULL;
 
 	ret->path = btrfs_alloc_path();
-	if (!ret) {
+	if (!ret->path) {
 		kfree(ret);
 		return NULL;
 	}