[OPW,kernel,02/10] staging: dgap: Replace memcpy with struct assignment
diff mbox

Message ID 89e59cdea56b0ad3285cdea2cc291cfe10e40e05.1412524266.git.tapaswenipathak@gmail.com
State New, archived
Headers show

Commit Message

Tapasweni Pathak Oct. 5, 2014, 4:02 p.m. UTC
This patch replaces this kind of memcpy() uses as it is
error prone. It is replaced with a struct assignment as it is
typesafe and much easier to read.

This is done by Coccinelle. Coccinelle script used:
// <smpl>
@@
identifier struct_name;
struct struct_name to;
struct struct_name from;
expression E;
@@
-memcpy(&(to), &(from), E);
+to = from;
// </smpl>

Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com>
---
 drivers/staging/dgap/dgap.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
1.7.9.5

Patch
diff mbox

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index d0be1ce..daf09be 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -3140,7 +3140,7 @@  static int dgap_tty_digigeta(struct channel_t *ch,
 	memset(&tmp, 0, sizeof(tmp));

 	spin_lock_irqsave(&ch->ch_lock, lock_flags);
-	memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
+	tmp = ch->ch_digi;
 	spin_unlock_irqrestore(&ch->ch_lock, lock_flags);

 	if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
@@ -3170,7 +3170,7 @@  static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
 	spin_lock_irqsave(&bd->bd_lock, lock_flags);
 	spin_lock_irqsave(&ch->ch_lock, lock_flags2);

-	memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
+	ch->ch_digi = new_digi;

 	if (ch->ch_digi.digi_maxcps < 1)
 		ch->ch_digi.digi_maxcps = 1;