From patchwork Tue Oct 23 19:57:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1632541 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7B3CE3FD4E for ; Tue, 23 Oct 2012 20:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933465Ab2JWUBw (ORCPT ); Tue, 23 Oct 2012 16:01:52 -0400 Received: from mail-yh0-f46.google.com ([209.85.213.46]:49915 "EHLO mail-yh0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757502Ab2JWT7O (ORCPT ); Tue, 23 Oct 2012 15:59:14 -0400 Received: by mail-yh0-f46.google.com with SMTP id m54so823993yhm.19 for ; Tue, 23 Oct 2012 12:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=x0mYEnHP4KCLjGT9N1EICaHpusNS0xnajZUlmxCl980=; b=HehcUFL5c6EILX6CWLP+nuQYLvotNCrqhh7i/Tl1lQiT4zxRPnS3Ni0NqEvt9wGUQO RCeAQZNld9x7b6CdHw+RtLKzhcrmw2+9W7Na82zRrRkdPbLL6R8lUYNSlB+gvCjy5hZ+ E2rqtYO05PdBkUxc17ql0JPCGIzuzxZZ3qs/VQfiIsqLojHnGMoZduBT6fOUmpRzB6mx hiDLi8cqE9874r1E0w1oP5P6hz6sOWMVULQBrXoPcBvo8NqhGKVXM2Cnx+TFG/huJq7e /IpEz8klI+RFbH3oa2DiEsr9sNmtmzJiQyBRmP23HV1cL7vr1au08sPXLeYRqIN5cghQ 7qVA== Received: by 10.100.233.37 with SMTP id f37mr2602544anh.48.1351022354117; Tue, 23 Oct 2012 12:59:14 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.59.11 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:59:13 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Peter Senna Tschudin Subject: [PATCH 16/23] cx88: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:19 -0300 Message-Id: <1351022246-8201-16-git-send-email-elezegarcia@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1351022246-8201-1-git-send-email-elezegarcia@gmail.com> References: <1351022246-8201-1-git-send-email-elezegarcia@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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/) // @@ identifier struct_name; struct struct_name to; struct struct_name from; expression E; @@ -memcpy(&(to), &(from), E); +to = from; // Signed-off-by: Peter Senna Tschudin Signed-off-by: Ezequiel Garcia --- drivers/media/pci/cx88/cx88-cards.c | 2 +- drivers/media/pci/cx88/cx88-i2c.c | 3 +-- drivers/media/pci/cx88/cx88-vp3054-i2c.c | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c index 0c25524..e2e0b8f 100644 --- a/drivers/media/pci/cx88/cx88-cards.c +++ b/drivers/media/pci/cx88/cx88-cards.c @@ -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; diff --git a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c index de0f1af..cf2d696 100644 --- a/drivers/media/pci/cx88/cx88-i2c.c +++ b/drivers/media/pci/cx88/cx88-i2c.c @@ -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; diff --git a/drivers/media/pci/cx88/cx88-vp3054-i2c.c b/drivers/media/pci/cx88/cx88-vp3054-i2c.c index d77f8ec..deede6e 100644 --- a/drivers/media/pci/cx88/cx88-vp3054-i2c.c +++ b/drivers/media/pci/cx88/cx88-vp3054-i2c.c @@ -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,