linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] v4l: ioctl: Use kmalloc to allocate a small chunk of memory
@ 2020-12-20 21:30 Sakari Ailus
  2020-12-20 21:47 ` Laurent Pinchart
  0 siblings, 1 reply; 2+ messages in thread
From: Sakari Ailus @ 2020-12-20 21:30 UTC (permalink / raw)
  To: linux-media
  Cc: Arnd Bergmann, Hans Verkuil, Laurent Pinchart, Mauro Carvalho Chehab

kvmalloc() was used to release the temporary memory buffer that was used
to contain both the IOCTL argument as well as a possible array argument
that could have been large. Now that the two are separated, the IOCTL
argument is known to be small in size. Use kmalloc to allocate it instead
of kvmalloc. Similarly for releasing it.

Suggested-by: Arnd Bergmann <arnd@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 9906b41004e9b..8d5d9c39c1622 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -3300,7 +3300,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
 			parg = sbuf;
 		} else {
 			/* too big to allocate from stack */
-			mbuf = kvmalloc(ioc_size, GFP_KERNEL);
+			mbuf = kmalloc(ioc_size, GFP_KERNEL);
 			if (NULL == mbuf)
 				return -ENOMEM;
 			parg = mbuf;
@@ -3377,7 +3377,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
 		err = -EFAULT;
 out:
 	kvfree(array_buf);
-	kvfree(mbuf);
+	kfree(mbuf);
 	return err;
 }
 
-- 
2.20.1


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

* Re: [PATCH 1/1] v4l: ioctl: Use kmalloc to allocate a small chunk of memory
  2020-12-20 21:30 [PATCH 1/1] v4l: ioctl: Use kmalloc to allocate a small chunk of memory Sakari Ailus
@ 2020-12-20 21:47 ` Laurent Pinchart
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2020-12-20 21:47 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, Arnd Bergmann, Hans Verkuil, Mauro Carvalho Chehab

Hi Sajari,

Thank you for the patch.

On Sun, Dec 20, 2020 at 11:30:12PM +0200, Sakari Ailus wrote:
> kvmalloc() was used to release the temporary memory buffer that was used
> to contain both the IOCTL argument as well as a possible array argument
> that could have been large. Now that the two are separated, the IOCTL
> argument is known to be small in size. Use kmalloc to allocate it instead
> of kvmalloc. Similarly for releasing it.
> 
> Suggested-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 9906b41004e9b..8d5d9c39c1622 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -3300,7 +3300,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
>  			parg = sbuf;
>  		} else {
>  			/* too big to allocate from stack */
> -			mbuf = kvmalloc(ioc_size, GFP_KERNEL);
> +			mbuf = kmalloc(ioc_size, GFP_KERNEL);
>  			if (NULL == mbuf)
>  				return -ENOMEM;
>  			parg = mbuf;
> @@ -3377,7 +3377,7 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,
>  		err = -EFAULT;
>  out:
>  	kvfree(array_buf);
> -	kvfree(mbuf);
> +	kfree(mbuf);
>  	return err;
>  }
>  

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2020-12-20 21:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 21:30 [PATCH 1/1] v4l: ioctl: Use kmalloc to allocate a small chunk of memory Sakari Ailus
2020-12-20 21:47 ` Laurent Pinchart

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).