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

Message ID 5224de1745513e9881ef7d3b9801fdd54422bd03.1412524266.git.tapaswenipathak@gmail.com
State New, archived
Headers show

Commit Message

Tapasweni Pathak Oct. 5, 2014, 4:03 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/dgnc/dgnc_tty.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
1.7.9.5

Patch
diff mbox

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 03c1506..2a4b58e 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -2410,7 +2410,7 @@  static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retin
 	memset(&tmp, 0, sizeof(tmp));

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

 	if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
@@ -2472,7 +2472,7 @@  static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_i
 	if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
 		ch->ch_mostat |= (UART_MCR_DTR);

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

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