From patchwork Wed Sep 14 07:31:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 669761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3sYtXR3xz4z9sxb; Wed, 14 Sep 2016 17:31:51 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1bk4fb-0000iF-Oa; Wed, 14 Sep 2016 07:31:47 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1bk4fW-0000hp-F4 for fwts-devel@lists.ubuntu.com; Wed, 14 Sep 2016 07:31:42 +0000 Received: from [175.181.155.183] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1bk4fV-0007Ut-LV; Wed, 14 Sep 2016 07:31:42 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] efi_runtime: use memdup_user() as a cleanup Date: Wed, 14 Sep 2016 15:31:35 +0800 Message-Id: <1473838295-12528-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 1.9.1 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com Got warning when upstreaming efi_runtime driver drivers/firmware/efi/test/efi_test.c:269:8-15: WARNING opportunity for memdup_user Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives Generated by: coccinelle/api/memdup_user.coc Signed-off-by: Ivan Hu Acked-by: Colin Ian King Acked-by: Alex Hung --- efi_runtime/efi_runtime.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c index 594eccd..19f8103 100644 --- a/efi_runtime/efi_runtime.c +++ b/efi_runtime/efi_runtime.c @@ -284,14 +284,10 @@ static long efi_runtime_set_variable(unsigned long arg) return rv; } - data = kmalloc(setvariable.data_size, GFP_KERNEL); - if (!data) { + data = memdup_user(setvariable.data, setvariable.data_size); + if (IS_ERR(data)) { kfree(name); - return -ENOMEM; - } - if (copy_from_user(data, setvariable.data, setvariable.data_size)) { - rv = -EFAULT; - goto out; + return PTR_ERR(data); } status = efi.set_variable(name, &vendor_guid,