From patchwork Tue Oct 23 19:57:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1632621 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E6719DF283 for ; Tue, 23 Oct 2012 20:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756945Ab2JWUET (ORCPT ); Tue, 23 Oct 2012 16:04:19 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:61542 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933417Ab2JWT7C (ORCPT ); Tue, 23 Oct 2012 15:59:02 -0400 Received: by mail-gg0-f174.google.com with SMTP id k5so820742ggd.19 for ; Tue, 23 Oct 2012 12:59:01 -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=47LXVPL7bhGvukGspIF+mvSnljztoWsOJq7OxQVaAdk=; b=gwnjqB6na6TS9rfU+p32Lkpw5hkKSlcWeJegV8kvLJQRCRCLevEaeInMXeHVC09o/d sSyl5k34Oh4GPmz4p8meZBg6XZIC+PHAXb8oyqSq9ejahmY4y8XrUzf77v2CalUmJdOL DFgBrJ3DwTpWRDyHoDZZ3V74xxgH3izRheGhwDH45fwEE3x78CTX9vfeoHAGBdooKmwc 2m4BysBC1y4ruzH1qmyKPbDegtOsML0BuE5h540Vz+EvTvIB1BgbMch7eFXOCPUeM2X6 MQo++9mSs01dHUHYh4iteSDUK5t8ZjoteHPIw2z5lifAyUMcltIJ7uT2B6vj4q5Qt+c7 5NWw== Received: by 10.236.144.165 with SMTP id n25mr12919106yhj.61.1351022341561; Tue, 23 Oct 2012 12:59:01 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.58.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:59:01 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Peter Senna Tschudin Subject: [PATCH 11/23] au0828: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:14 -0300 Message-Id: <1351022246-8201-11-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/usb/au0828/au0828-cards.c | 2 +- drivers/media/usb/au0828/au0828-i2c.c | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/au0828/au0828-cards.c b/drivers/media/usb/au0828/au0828-cards.c index 448361c..8830d6d 100644 --- a/drivers/media/usb/au0828/au0828-cards.c +++ b/drivers/media/usb/au0828/au0828-cards.c @@ -192,7 +192,7 @@ void au0828_card_setup(struct au0828_dev *dev) dprintk(1, "%s()\n", __func__); - memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board)); + dev->board = au0828_boards[dev->boardnr]; if (dev->i2c_rc == 0) { dev->i2c_client.addr = 0xa0 >> 1; diff --git a/drivers/media/usb/au0828/au0828-i2c.c b/drivers/media/usb/au0828/au0828-i2c.c index 4ded17f..71fbe59 100644 --- a/drivers/media/usb/au0828/au0828-i2c.c +++ b/drivers/media/usb/au0828/au0828-i2c.c @@ -364,12 +364,9 @@ int au0828_i2c_register(struct au0828_dev *dev) { dprintk(1, "%s()\n", __func__); - memcpy(&dev->i2c_adap, &au0828_i2c_adap_template, - sizeof(dev->i2c_adap)); - memcpy(&dev->i2c_algo, &au0828_i2c_algo_template, - sizeof(dev->i2c_algo)); - memcpy(&dev->i2c_client, &au0828_i2c_client_template, - sizeof(dev->i2c_client)); + dev->i2c_adap = au0828_i2c_adap_template; + dev->i2c_algo = au0828_i2c_algo_template; + dev->i2c_client = au0828_i2c_client_template; dev->i2c_adap.dev.parent = &dev->usbdev->dev;