* [PATCH v2] uvc: Replace memcpy with struct assignment
@ 2013-01-14 18:22 Ezequiel Garcia
2013-01-21 10:04 ` Laurent Pinchart
0 siblings, 1 reply; 2+ messages in thread
From: Ezequiel Garcia @ 2013-01-14 18:22 UTC (permalink / raw)
To: linux-media; +Cc: Ezequiel Garcia, Laurent Pinchart, Peter Senna Tschudin
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 <laurent.pinchart@ideasonboard.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
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(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 516a5b1..f2f6443 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -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.) */
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 8e05604..36e79ed 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -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. */
--
1.7.4.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] uvc: Replace memcpy with struct assignment
2013-01-14 18:22 [PATCH v2] uvc: Replace memcpy with struct assignment Ezequiel Garcia
@ 2013-01-21 10:04 ` Laurent Pinchart
0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2013-01-21 10:04 UTC (permalink / raw)
To: Ezequiel Garcia; +Cc: linux-media, Peter Senna Tschudin
Hi,
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 <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
> Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Thank you for the patch. I've applied it to my tree.
> ---
> 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(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c
> b/drivers/media/usb/uvc/uvc_ctrl.c index 516a5b1..f2f6443 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -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.) */
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> b/drivers/media/usb/uvc/uvc_v4l2.c index 8e05604..36e79ed 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -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. */
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-01-21 10:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 18:22 [PATCH v2] uvc: Replace memcpy with struct assignment Ezequiel Garcia
2013-01-21 10:04 ` 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).