From patchwork Mon Oct 14 15:18:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geyslan G. Bem" X-Patchwork-Id: 3037061 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E265BF924 for ; Mon, 14 Oct 2013 15:23:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 753D320165 for ; Mon, 14 Oct 2013 15:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE763201CE for ; Mon, 14 Oct 2013 15:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756771Ab3JNPX2 (ORCPT ); Mon, 14 Oct 2013 11:23:28 -0400 Received: from mail-ve0-f177.google.com ([209.85.128.177]:55542 "EHLO mail-ve0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755699Ab3JNPX1 (ORCPT ); Mon, 14 Oct 2013 11:23:27 -0400 Received: by mail-ve0-f177.google.com with SMTP id cz12so724258veb.36 for ; Mon, 14 Oct 2013 08:23:27 -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; bh=qwsAL1bs/UNeTVM2lmyeabhQ9/EHfFUshciCq0xPmFc=; b=QCfB3rUX38y6a5qcQ5EwOkEvcB+JUawfLTm5XicJbFMuNwAs0fRJTrawNvY+p5JjpM GYom0R4R3zGXvNKau21/EupL0J41kzuqc+/t7P4AoFq98XTUPDCaojUQ75ZqGYZar4cV j4mMasCkMLIJZ0+/zHxp6SWNWALB38RQT0J4JRAo3o2te58RAMxXs67J4fgBn3ub8quk xYbCXvvQhI9GuYUJG6pdzZHmwwhn1C3/X5Z+vKO0KcdQj9mYYQra3BHv3KM+amg8ftgG A9C/mNQMtqkBI+DoaijTzLAWAp0pnvWdqPzH9YV8/zLQCEfZPibO0vLTjX4mGE1iXRNg HDpg== X-Received: by 10.52.33.147 with SMTP id r19mr155496vdi.37.1381764207038; Mon, 14 Oct 2013 08:23:27 -0700 (PDT) Received: from localhost.localdomain (201-4-216-47.user.veloxzone.com.br. [201.4.216.47]) by mx.google.com with ESMTPSA id k17sm81690296vdh.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Oct 2013 08:23:26 -0700 (PDT) From: "Geyslan G. Bem" To: chris.mason@fusionio.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-br@googlegroups.com, "Geyslan G. Bem" Subject: [PATCH] btrfs: simplify kmalloc+copy_from_user to memdup_user Date: Mon, 14 Oct 2013 12:18:25 -0300 Message-Id: <1381763905-18803-1-git-send-email-geyslan@gmail.com> X-Mailer: git-send-email 1.8.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives The semantic patch that makes this report is available in scripts/coccinelle/api/memdup_user.cocci. More information about semantic patching is available at http://coccinelle.lip6.fr/ Signed-off-by: Geyslan G. Bem --- fs/btrfs/ioctl.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9d46f60..f0e3517 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2727,15 +2727,10 @@ static long btrfs_ioctl_file_extent_same(struct file *file, size = sizeof(tmp) + tmp.dest_count * sizeof(struct btrfs_ioctl_same_extent_info); - same = kmalloc(size, GFP_NOFS); - if (!same) { - ret = -EFAULT; - goto out; - } + same = memdup_user((struct btrfs_ioctl_same_args __user *)argp, size); - if (copy_from_user(same, - (struct btrfs_ioctl_same_args __user *)argp, size)) { - ret = -EFAULT; + if (IS_ERR(same)) { + ret = PTR_ERR(same); goto out; }