From patchwork Tue Oct 23 19:57:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1632491 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 8AAD9DF283 for ; Tue, 23 Oct 2012 20:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933463Ab2JWT7W (ORCPT ); Tue, 23 Oct 2012 15:59:22 -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 S1757516Ab2JWT7T (ORCPT ); Tue, 23 Oct 2012 15:59:19 -0400 Received: by mail-yh0-f46.google.com with SMTP id m54so823993yhm.19 for ; Tue, 23 Oct 2012 12:59:19 -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=T5T8bXrmZ6GpPuOF9LZu1KUovGwpNPu653ifmykLN2g=; b=GVy8dXZVhYE7uKq9yVImYpKBnsxJ0e2mwnnfPtj20WDhcpTHqjLI+Y+POgcFvay3fe S+K7W2cH4JLLMp9TRn8GJK9HTT+djOjZTRhYCg5o0lMAMGBju/YEXJrxtj3oyuwVA4sm jM8qJLSAxE3AqurH6qPCSqI8S9xVC/UWIp52OSYVzJluhDWkH17YbrKN9gbj8zv79U3G 4yybpoX54CfSoCdfaxa/CKTofcq5nvcf4phfRfwQpUQStjfv2aINjCz4VmbyZ86QK6dC M06NuW5L5NLENledlkweljT21feb8CUzKzLTgNmX1Y+iEUbFxSs0i4uW8eyzJdPD1F3w 7BxA== Received: by 10.236.35.209 with SMTP id u57mr12652062yha.15.1351022359419; Tue, 23 Oct 2012 12:59:19 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.59.16 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:59:18 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Andy Walls , Peter Senna Tschudin Subject: [PATCH 18/23] cx18: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:21 -0300 Message-Id: <1351022246-8201-18-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; // Cc: Andy Walls Signed-off-by: Peter Senna Tschudin Signed-off-by: Ezequiel Garcia Signed-off-by: Andy Walls --- drivers/media/pci/cx18/cx18-i2c.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c index 51609d5..930d40f 100644 --- a/drivers/media/pci/cx18/cx18-i2c.c +++ b/drivers/media/pci/cx18/cx18-i2c.c @@ -240,15 +240,13 @@ int init_cx18_i2c(struct cx18 *cx) for (i = 0; i < 2; i++) { /* Setup algorithm for adapter */ - memcpy(&cx->i2c_algo[i], &cx18_i2c_algo_template, - sizeof(struct i2c_algo_bit_data)); + cx->i2c_algo[i] = cx18_i2c_algo_template; cx->i2c_algo_cb_data[i].cx = cx; cx->i2c_algo_cb_data[i].bus_index = i; cx->i2c_algo[i].data = &cx->i2c_algo_cb_data[i]; /* Setup adapter */ - memcpy(&cx->i2c_adap[i], &cx18_i2c_adap_template, - sizeof(struct i2c_adapter)); + cx->i2c_adap[i] = cx18_i2c_adap_template; cx->i2c_adap[i].algo_data = &cx->i2c_algo[i]; sprintf(cx->i2c_adap[i].name + strlen(cx->i2c_adap[i].name), " #%d-%d", cx->instance, i);