[media] uvcvideo: Use memdup_user() rather than duplicating its implementation
authorMarkus Elfring <elfring@users.sourceforge.net>
Fri, 19 Aug 2016 08:50:05 +0000 (05:50 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 23 Nov 2016 22:06:41 +0000 (20:06 -0200)
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/usb/uvc/uvc_v4l2.c

index 05eed4be25df2ba22e68b016eb18a40cb8516a59..a7e12fd20adcc340aae7a28691e0a11489a61b53 100644 (file)
@@ -70,14 +70,9 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
                }
 
                size = xmap->menu_count * sizeof(*map->menu_info);
-               map->menu_info = kmalloc(size, GFP_KERNEL);
-               if (map->menu_info == NULL) {
-                       ret = -ENOMEM;
-                       goto done;
-               }
-
-               if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
-                       ret = -EFAULT;
+               map->menu_info = memdup_user(xmap->menu_info, size);
+               if (IS_ERR(map->menu_info)) {
+                       ret = PTR_ERR(map->menu_info);
                        goto done;
                }