linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/23] uvc: Replace memcpy with struct assignment
@ 2012-10-23 19:57 Ezequiel Garcia
  2012-10-23 19:57 ` [PATCH 02/23] cx231xx: " Ezequiel Garcia
                   ` (23 more replies)
  0 siblings, 24 replies; 37+ messages in thread
From: Ezequiel Garcia @ 2012-10-23 19:57 UTC (permalink / raw)
  To: linux-kernel, linux-media
  Cc: Julia.Lawall, kernel-janitors, 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.

Found by coccinelle. Hand patched and reviewed.
Tested by compilation only.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier struct_name;
struct struct_name to;
struct struct_name from;
expression E;
@@
-memcpy(&(to), &(from), E);
+to = from;
// </smpl>

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>
---
 drivers/media/usb/uvc/uvc_v4l2.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index f00db30..4fc8737 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -314,7 +314,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;
 
@@ -386,7 +386,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);
 
@@ -397,7 +397,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] 37+ messages in thread

end of thread, other threads:[~2013-01-12 17:44 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-23 19:57 [PATCH 01/23] uvc: Replace memcpy with struct assignment Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 02/23] cx231xx: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 03/23] usbvision: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 04/23] sn9c102: " Ezequiel Garcia
2012-10-24  0:50   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 05/23] pwc: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 06/23] pvrusb2: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 07/23] hdpvr: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 08/23] cx25840: " Ezequiel Garcia
2012-10-23 22:20   ` Andy Walls
2012-10-23 19:57 ` [PATCH 09/23] zr36067: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 10/23] dvb-usb/friio-fe: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 11/23] au0828: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 12/23] tuners/xc4000: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 13/23] tuners/xc2028: " Ezequiel Garcia
2012-10-23 22:36   ` Andy Walls
2012-10-23 19:57 ` [PATCH 14/23] tuners/tda18271: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 15/23] ivtv: " Ezequiel Garcia
2012-10-23 22:08   ` Andy Walls
2012-10-24  0:28     ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 16/23] cx88: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 17/23] cx23885: " Ezequiel Garcia
2012-10-23 22:16   ` Andy Walls
2012-10-24  0:52     ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 18/23] cx18: " Ezequiel Garcia
2012-10-23 22:17   ` Andy Walls
2012-10-23 19:57 ` [PATCH 19/23] bttv: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 20/23] dvb-core: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 21/23] dvb-frontends: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 22/23] radio-wl1273: " Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 23/23] wl128x: " Ezequiel Garcia
2012-10-24 22:35 ` [PATCH 01/23] uvc: " Laurent Pinchart
2012-10-24 23:10   ` Andy Walls
2012-12-27 21:12 ` Ezequiel Garcia
2012-12-27 23:49   ` Mauro Carvalho Chehab
2013-01-10  0:19     ` Laurent Pinchart
2013-01-12 17:44       ` Ezequiel Garcia

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