[RH7] ploop: variable dereferenced before check 'fbd' in ploop_fb_get_reloc_block

Submitted by Vasily Averin on May 31, 2020, 1:23 p.m.

Details

Message ID 42014524-f7d4-7148-3cd9-da4226c88007@virtuozzo.com
State New
Series "ploop: variable dereferenced before check 'fbd' in ploop_fb_get_reloc_block"
Headers show

Commit Message

Vasily Averin May 31, 2020, 1:23 p.m.
found by smatch:
drivers/block/ploop/freeblks.c:469 ploop_fb_get_reloc_block() warn:
 variable dereferenced before check 'fbd' (see line 467)

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 drivers/block/ploop/freeblks.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/freeblks.c b/drivers/block/ploop/freeblks.c
index e210421..7a06b09 100644
--- a/drivers/block/ploop/freeblks.c
+++ b/drivers/block/ploop/freeblks.c
@@ -464,11 +464,12 @@  int ploop_fb_get_reloc_block(struct ploop_freeblks_desc *fbd,
 	cluster_t from_clu, to_clu;
 	iblock_t  from_iblk, to_iblk;
 	u32 free;
-	struct ploop_relocblks_extent *r_extent = fbd->fbd_lrb.ext;
+	struct ploop_relocblks_extent *r_extent;
 
 	if (!fbd)
 		return -1;
 
+	r_extent = fbd->fbd_lrb.ext;
 	/* whole range is drained? */
 	if (r_extent == NULL)
 		return -1;

Comments

Kirill Tkhai June 1, 2020, 8:22 a.m.
On 31.05.2020 16:23, Vasily Averin wrote:
> found by smatch:
> drivers/block/ploop/freeblks.c:469 ploop_fb_get_reloc_block() warn:
>  variable dereferenced before check 'fbd' (see line 467)
> 
> Signed-off-by: Vasily Averin <vvs@virtuozzo.com>

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  drivers/block/ploop/freeblks.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/ploop/freeblks.c b/drivers/block/ploop/freeblks.c
> index e210421..7a06b09 100644
> --- a/drivers/block/ploop/freeblks.c
> +++ b/drivers/block/ploop/freeblks.c
> @@ -464,11 +464,12 @@ int ploop_fb_get_reloc_block(struct ploop_freeblks_desc *fbd,
>  	cluster_t from_clu, to_clu;
>  	iblock_t  from_iblk, to_iblk;
>  	u32 free;
> -	struct ploop_relocblks_extent *r_extent = fbd->fbd_lrb.ext;
> +	struct ploop_relocblks_extent *r_extent;
>  
>  	if (!fbd)
>  		return -1;
>  
> +	r_extent = fbd->fbd_lrb.ext;
>  	/* whole range is drained? */
>  	if (r_extent == NULL)
>  		return -1;
>