From patchwork Tue Oct 23 19:57:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1634951 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 938F63FD85 for ; Tue, 23 Oct 2012 21:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757453Ab2JWT6o (ORCPT ); Tue, 23 Oct 2012 15:58:44 -0400 Received: from mail-ye0-f174.google.com ([209.85.213.174]:40896 "EHLO mail-ye0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756855Ab2JWT6m (ORCPT ); Tue, 23 Oct 2012 15:58:42 -0400 Received: by mail-ye0-f174.google.com with SMTP id m12so525603yen.19 for ; Tue, 23 Oct 2012 12:58:41 -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=Fdk1d5n//MJwRMpOC4S0dEXA4ESBvIzm6tql06AGbFY=; b=O8d7B+aD8u1JNW6ZL/tNmAjZU9J1Wh3v4aYCozC9MGfWBkrq9CobbnXwEeSimF5HDV 0jqueKtD9PjLHxxnhJAnZmCq0qCcqMg6WcMMmFwUfKVNsBLYVvnP/HhrKxvhQPZI9UqP fFnCaSiF8gsc/+kjAJ8Rtme8/evS7UN3SaSl+My07TVCcqG8NzvQ7BJ9frHO7HvZZvsh IGeZizMJgq4oclXVVJPAiXNLaMIUB7XItoc5NEq6uSUPSzx48kXp54s3jpdKKFS2gMW8 1w7OyDL+gE40rb8FPZ5eHW1dD9YKfX/2LM3WEgyEYS+s/k5Hx03ngCaB9AFUzVDwdJu9 qDGg== Received: by 10.236.77.39 with SMTP id c27mr12867285yhe.102.1351022321393; Tue, 23 Oct 2012 12:58:41 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.58.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:58:40 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Peter Senna Tschudin Subject: [PATCH 03/23] usbvision: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:06 -0300 Message-Id: <1351022246-8201-3-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/usbvision/usbvision-i2c.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/usbvision/usbvision-i2c.c b/drivers/media/usb/usbvision/usbvision-i2c.c index 89fec02..ba262a3 100644 --- a/drivers/media/usb/usbvision/usbvision-i2c.c +++ b/drivers/media/usb/usbvision/usbvision-i2c.c @@ -189,8 +189,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision) if (usbvision->registered_i2c) return 0; - memcpy(&usbvision->i2c_adap, &i2c_adap_template, - sizeof(struct i2c_adapter)); + usbvision->i2c_adap = i2c_adap_template; sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, usbvision->dev->bus->busnum, usbvision->dev->devpath);