diff mbox series

media: vb2: be sure to free on errors

Message ID e1b3d00067767ceb39da5e0014b320835b443908.1542974835.git.mchehab+samsung@kernel.org (mailing list archive)
State New, archived
Headers show
Series media: vb2: be sure to free on errors | expand

Commit Message

Mauro Carvalho Chehab Nov. 23, 2018, 12:07 p.m. UTC
As reported by smatch:
drivers/media/common/videobuf2/videobuf2-core.c: drivers/media/common/videobuf2/videobuf2-core.c:2159 vb2_mmap() warn: inconsistent returns 'mutex:&q->mmap_lock'.
  Locked on:   line 2148
  Unlocked on: line 2100
               line 2108
               line 2113
               line 2118
               line 2156
               line 2159

There is one error condition that doesn't unlock a mutex.

Fixes: cd26d1c4d1bc ("media: vb2: vb2_mmap: move lock up")
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
 drivers/media/common/videobuf2/videobuf2-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Hans Verkuil Nov. 23, 2018, 12:11 p.m. UTC | #1
On 11/23/2018 01:07 PM, Mauro Carvalho Chehab wrote:
> As reported by smatch:
> drivers/media/common/videobuf2/videobuf2-core.c: drivers/media/common/videobuf2/videobuf2-core.c:2159 vb2_mmap() warn: inconsistent returns 'mutex:&q->mmap_lock'.
>   Locked on:   line 2148
>   Unlocked on: line 2100
>                line 2108
>                line 2113
>                line 2118
>                line 2156
>                line 2159
> 
> There is one error condition that doesn't unlock a mutex.
> 
> Fixes: cd26d1c4d1bc ("media: vb2: vb2_mmap: move lock up")
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

Hmm, that's embarrassing... I should have seen that smatch warning.

Regards,

	Hans

> ---
>  drivers/media/common/videobuf2/videobuf2-core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index 04d1250747cf..0ca81d495bda 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2145,7 +2145,8 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>  	if (length < (vma->vm_end - vma->vm_start)) {
>  		dprintk(1,
>  			"MMAP invalid, as it would overflow buffer length\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto unlock;
>  	}
>  
>  	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
>
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 04d1250747cf..0ca81d495bda 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -2145,7 +2145,8 @@  int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 	if (length < (vma->vm_end - vma->vm_start)) {
 		dprintk(1,
 			"MMAP invalid, as it would overflow buffer length\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto unlock;
 	}
 
 	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);