Skip to content

Commit

Permalink
[media] cx88: Replace memcpy with struct assignment
Browse files Browse the repository at this point in the history
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>

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Ezequiel Garcia authored and Mauro Carvalho Chehab committed Dec 27, 2012
1 parent 01a5cbe commit b523774
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/media/pci/cx88/cx88-cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,7 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
cx88_card_list(core, pci);
}

memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board));
core->board = cx88_boards[core->boardnr];

if (!core->board.num_frontends && (core->board.mpeg & CX88_MPEG_DVB))
core->board.num_frontends = 1;
Expand Down
3 changes: 1 addition & 2 deletions drivers/media/pci/cx88/cx88-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
if (i2c_udelay<5)
i2c_udelay=5;

memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
sizeof(core->i2c_algo));
core->i2c_algo = cx8800_i2c_algo_template;


core->i2c_adap.dev.parent = &pci->dev;
Expand Down
3 changes: 1 addition & 2 deletions drivers/media/pci/cx88/cx88-vp3054-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
return -ENOMEM;
dev->vp3054 = vp3054_i2c;

memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template,
sizeof(vp3054_i2c->algo));
vp3054_i2c->algo = vp3054_i2c_algo_template;

vp3054_i2c->adap.dev.parent = &dev->pci->dev;
strlcpy(vp3054_i2c->adap.name, core->name,
Expand Down

0 comments on commit b523774

Please sign in to comment.