All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <elezegarcia@gmail.com>
To: <linux-kernel@vger.kernel.org>, <linux-media@vger.kernel.org>
Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org,
	Ezequiel Garcia <elezegarcia@gmail.com>,
	Mike Isely <isely@pobox.com>,
	Peter Senna Tschudin <peter.senna@gmail.com>
Subject: [PATCH 06/23] pvrusb2: Replace memcpy with struct assignment
Date: Tue, 23 Oct 2012 16:57:09 -0300	[thread overview]
Message-ID: <1351022246-8201-6-git-send-email-elezegarcia@gmail.com> (raw)
In-Reply-To: <1351022246-8201-1-git-send-email-elezegarcia@gmail.com>

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: Mike Isely <isely@pobox.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
 drivers/media/usb/pvrusb2/pvrusb2-encoder.c  |    3 +--
 drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c |    4 ++--
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c     |    2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
index e046fda..f7702ae 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
@@ -422,8 +422,7 @@ int pvr2_encoder_adjust(struct pvr2_hdw *hdw)
 		pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 			   "Error from cx2341x module code=%d",ret);
 	} else {
-		memcpy(&hdw->enc_cur_state,&hdw->enc_ctl_state,
-		       sizeof(struct cx2341x_mpeg_params));
+		hdw->enc_cur_state = hdw->enc_ctl_state;
 		hdw->enc_cur_valid = !0;
 	}
 	return ret;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
index 885ce11..9691156 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -649,8 +649,8 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
 	}
 
 	// Configure the adapter and set up everything else related to it.
-	memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap));
-	memcpy(&hdw->i2c_algo,&pvr2_i2c_algo_template,sizeof(hdw->i2c_algo));
+	hdw->i2c_adap = pvr2_i2c_adap_template;
+	hdw->i2c_algo = pvr2_i2c_algo_template;
 	strlcpy(hdw->i2c_adap.name,hdw->name,sizeof(hdw->i2c_adap.name));
 	hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev;
 	hdw->i2c_adap.algo = &hdw->i2c_algo;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index db249ca..5b622ec 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -1339,7 +1339,7 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
 		return;
 	}
 
-	memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
+	dip->devbase = vdev_template;
 	dip->devbase.release = pvr2_video_device_release;
 	dip->devbase.ioctl_ops = &pvr2_ioctl_ops;
 	{
-- 
1.7.4.4


WARNING: multiple messages have this Message-ID (diff)
From: Ezequiel Garcia <elezegarcia@gmail.com>
To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org,
	Ezequiel Garcia <elezegarcia@gmail.com>,
	Mike Isely <isely@pobox.com>,
	Peter Senna Tschudin <peter.senna@gmail.com>
Subject: [PATCH 06/23] pvrusb2: Replace memcpy with struct assignment
Date: Tue, 23 Oct 2012 19:57:09 +0000	[thread overview]
Message-ID: <1351022246-8201-6-git-send-email-elezegarcia@gmail.com> (raw)
In-Reply-To: <1351022246-8201-1-git-send-email-elezegarcia@gmail.com>

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: Mike Isely <isely@pobox.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
 drivers/media/usb/pvrusb2/pvrusb2-encoder.c  |    3 +--
 drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c |    4 ++--
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c     |    2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
index e046fda..f7702ae 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
@@ -422,8 +422,7 @@ int pvr2_encoder_adjust(struct pvr2_hdw *hdw)
 		pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 			   "Error from cx2341x module code=%d",ret);
 	} else {
-		memcpy(&hdw->enc_cur_state,&hdw->enc_ctl_state,
-		       sizeof(struct cx2341x_mpeg_params));
+		hdw->enc_cur_state = hdw->enc_ctl_state;
 		hdw->enc_cur_valid = !0;
 	}
 	return ret;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
index 885ce11..9691156 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -649,8 +649,8 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
 	}
 
 	// Configure the adapter and set up everything else related to it.
-	memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap));
-	memcpy(&hdw->i2c_algo,&pvr2_i2c_algo_template,sizeof(hdw->i2c_algo));
+	hdw->i2c_adap = pvr2_i2c_adap_template;
+	hdw->i2c_algo = pvr2_i2c_algo_template;
 	strlcpy(hdw->i2c_adap.name,hdw->name,sizeof(hdw->i2c_adap.name));
 	hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev;
 	hdw->i2c_adap.algo = &hdw->i2c_algo;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index db249ca..5b622ec 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -1339,7 +1339,7 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
 		return;
 	}
 
-	memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template));
+	dip->devbase = vdev_template;
 	dip->devbase.release = pvr2_video_device_release;
 	dip->devbase.ioctl_ops = &pvr2_ioctl_ops;
 	{
-- 
1.7.4.4


  parent reply	other threads:[~2012-10-23 19:58 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23 19:57 [PATCH 01/23] uvc: Replace memcpy with struct assignment Ezequiel Garcia
2012-10-23 19:57 ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 02/23] cx231xx: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 03/23] usbvision: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 04/23] sn9c102: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-24  0:50   ` 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   ` Ezequiel Garcia
2012-10-23 19:57 ` Ezequiel Garcia [this message]
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   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 08/23] cx25840: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 22:20   ` Andy Walls
2012-10-23 22:20     ` Andy Walls
2012-10-23 19:57 ` [PATCH 09/23] zr36067: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 10/23] dvb-usb/friio-fe: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 11/23] au0828: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 12/23] tuners/xc4000: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 13/23] tuners/xc2028: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 22:36   ` Andy Walls
2012-10-23 22:36     ` Andy Walls
2012-10-23 19:57 ` [PATCH 14/23] tuners/tda18271: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 15/23] ivtv: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 22:08   ` Andy Walls
2012-10-23 22:08     ` Andy Walls
2012-10-24  0:28     ` Ezequiel Garcia
2012-10-24  0:28       ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 16/23] cx88: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 17/23] cx23885: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 22:16   ` Andy Walls
2012-10-23 22:16     ` Andy Walls
2012-10-24  0:52     ` Ezequiel Garcia
2012-10-24  0:52       ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 18/23] cx18: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 22:17   ` Andy Walls
2012-10-23 22:17     ` Andy Walls
2012-10-23 19:57 ` [PATCH 19/23] bttv: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 20/23] dvb-core: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 21/23] dvb-frontends: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 22/23] radio-wl1273: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-23 19:57 ` [PATCH 23/23] wl128x: " Ezequiel Garcia
2012-10-23 19:57   ` Ezequiel Garcia
2012-10-24 22:35 ` [PATCH 01/23] uvc: " Laurent Pinchart
2012-10-24 22:35   ` Laurent Pinchart
2012-10-24 23:10   ` Andy Walls
2012-10-24 23:10     ` Andy Walls
2012-12-27 21:12 ` Ezequiel Garcia
2012-12-27 21:12   ` Ezequiel Garcia
2012-12-27 23:49   ` Mauro Carvalho Chehab
2012-12-27 23:49     ` Mauro Carvalho Chehab
2013-01-10  0:19     ` Laurent Pinchart
2013-01-10  0:19       ` Laurent Pinchart
2013-01-12 17:44       ` Ezequiel Garcia
2013-01-12 17:44         ` Ezequiel Garcia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351022246-8201-6-git-send-email-elezegarcia@gmail.com \
    --to=elezegarcia@gmail.com \
    --cc=Julia.Lawall@lip6.fr \
    --cc=isely@pobox.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=peter.senna@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.