Skip to contentSkip to conversation

v4l: ioctl: Use kmalloc to allocate a small chunk of memory

PATCH In review Sakari Ailus 2 participants 2 messages Dec 20, 2020 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l: ioctl: Use kmalloc to allocate a small chunk of memory

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.

---
 drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +2 -2
index 9906b41004e9b..8d5d9c39c1622 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Sajari,

Thank you for the patch.

Quoted 8 lines · Sakari Ailus

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.

Quoted 26 lines
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-ioctl.c +2 -2
index 9906b41004e9b..8d5d9c39c1622 100644
@@ -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;
 }
 
Signature · 3 lines
Regards,

Laurent Pinchart