From patchwork Tue Oct 23 19:57:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1634941 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 11C863FD85 for ; Tue, 23 Oct 2012 21:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933356Ab2JWVSP (ORCPT ); Tue, 23 Oct 2012 17:18:15 -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 S1756875Ab2JWT6o (ORCPT ); Tue, 23 Oct 2012 15:58:44 -0400 Received: by mail-gg0-f174.google.com with SMTP id k5so820742ggd.19 for ; Tue, 23 Oct 2012 12:58:43 -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=fIitub6wwa42f/WVXR9icngU8SxmfhRZ2J3PRSDXhCY=; b=fKyAjWg0smzO87OGBHfvVc48guTzgkWWUrCRdjUZUXNfuSQg/efw5xANZw4xMxhesW VHlMY/WIhW5s5Q+g+tWzxGZFyNCNjqX7SMDW3MrxQxYz9CcFcGbTndk0Za1qdtN0qDhr IoR1V9g7UUeOIp+2uBeGyQs1fRWP7yjUnPXimBlkXCqPtuONu/94Q+MkZMnMtbUJEDYC GzVJ3gz0o9rZKpsk6e/xz0zBh90ABO3tDe6DbSYc1vLlXo+dMqspbhjj5LQ3XlYYTccg HxLbbNEQHFZAbvAzJl5gChLYcmUQl4mcKf1hIdDq0UGEENxCn6cmt664zKz/g9Q28KMK T+bw== Received: by 10.236.77.229 with SMTP id d65mr12592568yhe.124.1351022323827; Tue, 23 Oct 2012 12:58:43 -0700 (PDT) Received: from localhost.localdomain ([186.153.120.250]) by mx.google.com with ESMTPS id k63sm12813347yhj.20.2012.10.23.12.58.41 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 12:58:43 -0700 (PDT) From: Ezequiel Garcia To: , Cc: Julia.Lawall@lip6.fr, kernel-janitors@vger.kernel.org, Ezequiel Garcia , Peter Senna Tschudin Subject: [PATCH 04/23] sn9c102: Replace memcpy with struct assignment Date: Tue, 23 Oct 2012 16:57:07 -0300 Message-Id: <1351022246-8201-4-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/sn9c102/sn9c102_core.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/sn9c102/sn9c102_core.c b/drivers/media/usb/sn9c102/sn9c102_core.c index 5bfc8e2..4cae6f8 100644 --- a/drivers/media/usb/sn9c102/sn9c102_core.c +++ b/drivers/media/usb/sn9c102/sn9c102_core.c @@ -2824,7 +2824,7 @@ sn9c102_vidioc_querybuf(struct sn9c102_device* cam, void __user * arg) b.index >= cam->nbuffers || cam->io != IO_MMAP) return -EINVAL; - memcpy(&b, &cam->frame[b.index].buf, sizeof(b)); + b = cam->frame[b.index].buf; if (cam->frame[b.index].vma_use_count) b.flags |= V4L2_BUF_FLAG_MAPPED; @@ -2927,7 +2927,7 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp, f->state = F_UNUSED; - memcpy(&b, &f->buf, sizeof(b)); + b = f->buf; if (f->vma_use_count) b.flags |= V4L2_BUF_FLAG_MAPPED;