From patchwork Tue Oct 23 19:57:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1632521 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 81B283FD4E for ; Tue, 23 Oct 2012 20:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757514Ab2JWT7T (ORCPT ); Tue, 23 Oct 2012 15:59: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 S1756781Ab2JWT7Q (ORCPT ); Tue, 23 Oct 2012 15:59:16 -0400 Received: by mail-gg0-f174.google.com with SMTP id k5so820742ggd.19 for ; Tue, 23 Oct 2012 12:59:16 -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=3E5vAq4RlAC3BCUfpbDq0a3utGWnElzRj2No2Ur4Q+Y=; b=KNDHO8dFdd4eK35QldEv9at9Fs3qIFDj32+vh9tXi7AYYMdf5hxLYcLP02QTbOYoh7 Vjn9MBfZecjlOmX2I9j0XnxYZhAuH6lsah5qFh9uj/hpzRvfdr5so/T7o4CWbXzUoJYW Varf5L6LK6zGRKJPQILDNd2D5SZYUDtXKnksvkm7bXM7ZX72FMswDh0aJdfZTbQ/ZRR1 B2q75dTrM/bqQmtPuVNLzy1xSJi29ImATVuPzHFfvyLxOAVs2M77KJ7yK1zKZVbomemg FFshfpjl8I9hBNaQAcUAL0SDejj3B3CfdyzI+wab5htYnLG5mV4+luLj1/SzZ4U6aNKV k7jA== Received: by 10.236.122.148 with SMTP id t20mr12657338yhh.19.1351022356417; Tue, 23 Oct 2012 12:59:16 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.59.14 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:59:15 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Peter Senna Tschudin Subject: [PATCH 17/23] cx23885: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:20 -0300 Message-Id: <1351022246-8201-17-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 Reviewed-by: Andy Walls Signed-off-by: Andy Walls --- drivers/media/pci/cx23885/cx23885-video.c | 3 +-- drivers/media/pci/cx23885/cx23888-ir.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c index 1a21926..62be144 100644 --- a/drivers/media/pci/cx23885/cx23885-video.c +++ b/drivers/media/pci/cx23885/cx23885-video.c @@ -1818,8 +1818,7 @@ int cx23885_video_register(struct cx23885_dev *dev) spin_lock_init(&dev->slock); /* Initialize VBI template */ - memcpy(&cx23885_vbi_template, &cx23885_video_template, - sizeof(cx23885_vbi_template)); + cx23885_vbi_template = cx23885_video_template; strcpy(cx23885_vbi_template.name, "cx23885-vbi"); dev->tvnorm = cx23885_video_template.current_norm; diff --git a/drivers/media/pci/cx23885/cx23888-ir.c b/drivers/media/pci/cx23885/cx23888-ir.c index c2bc39c..e448146 100644 --- a/drivers/media/pci/cx23885/cx23888-ir.c +++ b/drivers/media/pci/cx23885/cx23888-ir.c @@ -1236,13 +1236,11 @@ int cx23888_ir_probe(struct cx23885_dev *dev) cx23888_ir_write4(dev, CX23888_IR_IRQEN_REG, 0); mutex_init(&state->rx_params_lock); - memcpy(&default_params, &default_rx_params, - sizeof(struct v4l2_subdev_ir_parameters)); + default_params = default_rx_params; v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params); mutex_init(&state->tx_params_lock); - memcpy(&default_params, &default_tx_params, - sizeof(struct v4l2_subdev_ir_parameters)); + default_params = default_tx_params; v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params); } else { kfifo_free(&state->rx_kfifo);