diff mbox

[04/46,media] vivid-vid-out: use memdup_user()

Message ID 8e3336dbdbd26a56fb6817a4dc7cb31d860e8c5d.1409775488.git.m.chehab@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mauro Carvalho Chehab Sept. 3, 2014, 8:32 p.m. UTC
Instead of allocating and coping from __user, do it using
one atomic call. That makes the code simpler. Also,

Found by coccinelle.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

Comments

Hans Verkuil Sept. 3, 2014, 8:49 p.m. UTC | #1
On 09/03/2014 10:32 PM, Mauro Carvalho Chehab wrote:
> Instead of allocating and coping from __user, do it using
> one atomic call. That makes the code simpler. Also,

Also what?

Anyway, looks good to me:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

> 
> Found by coccinelle.
> 
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> 
> diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
> index c983461f29d5..8ed9f6d9f505 100644
> --- a/drivers/media/platform/vivid/vivid-vid-out.c
> +++ b/drivers/media/platform/vivid/vivid-vid-out.c
> @@ -897,14 +897,10 @@ int vidioc_s_fmt_vid_out_overlay(struct file *file, void *priv,
>  		return ret;
>  
>  	if (win->bitmap) {
> -		new_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> +		new_bitmap = memdup_user(win->bitmap, bitmap_size);
>  
> -		if (new_bitmap == NULL)
> -			return -ENOMEM;
> -		if (copy_from_user(new_bitmap, win->bitmap, bitmap_size)) {
> -			kfree(new_bitmap);
> -			return -EFAULT;
> -		}
> +		if (IS_ERR(new_bitmap))
> +			return PTR_ERR(new_bitmap);
>  	}
>  
>  	dev->overlay_out_top = win->w.top;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab Sept. 3, 2014, 8:57 p.m. UTC | #2
Em Wed, 03 Sep 2014 22:49:47 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 09/03/2014 10:32 PM, Mauro Carvalho Chehab wrote:
> > Instead of allocating and coping from __user, do it using
> > one atomic call. That makes the code simpler. Also,
> 
> Also what?

I added a comment about IS_ERR(new_bitmap), and returning
the error, but then I realized that the above is good enough,
but I forgot the "Also, " at the above line. Thanks for
pointing it.

> 
> Anyway, looks good to me:
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks!
Mauro
> 
> Regards,
> 
> 	Hans
> 
> > 
> > Found by coccinelle.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> > 
> > diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
> > index c983461f29d5..8ed9f6d9f505 100644
> > --- a/drivers/media/platform/vivid/vivid-vid-out.c
> > +++ b/drivers/media/platform/vivid/vivid-vid-out.c
> > @@ -897,14 +897,10 @@ int vidioc_s_fmt_vid_out_overlay(struct file *file, void *priv,
> >  		return ret;
> >  
> >  	if (win->bitmap) {
> > -		new_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> > +		new_bitmap = memdup_user(win->bitmap, bitmap_size);
> >  
> > -		if (new_bitmap == NULL)
> > -			return -ENOMEM;
> > -		if (copy_from_user(new_bitmap, win->bitmap, bitmap_size)) {
> > -			kfree(new_bitmap);
> > -			return -EFAULT;
> > -		}
> > +		if (IS_ERR(new_bitmap))
> > +			return PTR_ERR(new_bitmap);
> >  	}
> >  
> >  	dev->overlay_out_top = win->w.top;
> > 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index c983461f29d5..8ed9f6d9f505 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -897,14 +897,10 @@  int vidioc_s_fmt_vid_out_overlay(struct file *file, void *priv,
 		return ret;
 
 	if (win->bitmap) {
-		new_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+		new_bitmap = memdup_user(win->bitmap, bitmap_size);
 
-		if (new_bitmap == NULL)
-			return -ENOMEM;
-		if (copy_from_user(new_bitmap, win->bitmap, bitmap_size)) {
-			kfree(new_bitmap);
-			return -EFAULT;
-		}
+		if (IS_ERR(new_bitmap))
+			return PTR_ERR(new_bitmap);
 	}
 
 	dev->overlay_out_top = win->w.top;