uvc: Replace memcpy with struct assignment
Subsystems (2)
PATCH v2 1/1 uvc: Replace memcpy with struct assignment
This kind of memcpy() is error-prone. Its replacement with a struct assignment is prefered because it's type-safe and much easier to read.
Cc Laurent Pinchart <[email protected]>
Signed-off-by Peter Senna Tschudin <[email protected]>
Signed-off-by Ezequiel Garcia <[email protected]>
---
Changes from v1:
* Replaced a memcpy() in ucv_ctrl_add_info(),
originally missed by the coccinelle script.
drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvc_v4l2.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +1 -1
@@ -1839,7 +1839,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, {int ret =0 ; -memcpy (&ctrl->info, info,sizeof (*info)); + ctrl->info = *info;INIT_LIST_HEAD (&ctrl->info.mappings);/* Allocate an array to save control values (cur, def, max, etc.) */
drivers/media/usb/uvc/uvc_v4l2.c +3 -3
@@ -315,7 +315,7 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream, goto done; } -memcpy (&stream->ctrl, &probe,sizeof probe); + stream->ctrl = probe; stream->cur_format = format; stream->cur_frame = frame;
@@ -387,7 +387,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,return -EBUSY ; } -memcpy (&probe, &stream->ctrl,sizeof probe); + probe = stream->ctrl; probe.dwFrameInterval =uvc_try_frame_interval (stream->cur_frame, interval);
@@ -398,7 +398,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,return ret; } -memcpy (&stream->ctrl, &probe,sizeof probe); + stream->ctrl = probe;mutex_unlock (&stream->mutex);/* Return the actual frame period. */
Signature · 1 line
1.7.4.4
Laurent Pinchart
maintainerHi,
Quoted 6 lines · On Monday 14 January 2013 15:22:55 Ezequiel Garcia wrote:
This kind of
memcpy()is error-prone. Its replacement with a struct assignment is prefered because it's type-safe and much easier to read.Cc Laurent Pinchart <[email protected]>Signed-off-by Peter Senna Tschudin <[email protected]>Signed-off-by Ezequiel Garcia <[email protected]>
Thank you for the patch. I've applied it to my tree.
Quoted 53 lines
---
Changes from v1:
* Replaced amemcpy()inucv_ctrl_add_info(),
originally missed by the coccinelle script.drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvc_v4l2.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvc_ctrl.cindex 516a5b1..f2f6443 100644drivers/media/usb/uvc/uvc_ctrl.c +1
-1@@ -1839,7 +1839,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, { int ret = 0; -memcpy (&ctrl->info, info,sizeof (*info)); + ctrl->info = *info;INIT_LIST_HEAD (&ctrl->info.mappings);/* Allocate an array to save control values (cur, def, max, etc.) */ (quoted diff) +0
-0
b/drivers/media/usb/uvc/uvc_v4l2.cindex 8e05604..36e79ed 100644drivers/media/usb/uvc/uvc_v4l2.c +3
-3@@ -315,7 +315,7 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream, goto done; } -memcpy (&stream->ctrl, &probe,sizeof probe); + stream->ctrl = probe; stream->cur_format = format; stream->cur_frame = frame;@@ -387,7 +387,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, return -EBUSY ; } -memcpy (&probe, &stream->ctrl,sizeof probe); + probe = stream->ctrl; probe.dwFrameInterval =uvc_try_frame_interval (stream->cur_frame, interval);@@ -398,7 +398,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, return ret; } -memcpy (&stream->ctrl, &probe,sizeof probe); + stream->ctrl = probe;mutex_unlock (&stream->mutex);/* Return the actual frame period. */
Signature · 3 lines
Regards, Laurent Pinchart