Received: by 10.223.185.116 with SMTP id b49csp2767611wrg; Mon, 5 Mar 2018 08:22:32 -0800 (PST) X-Google-Smtp-Source: AG47ELvmHEHKZTGWZlrhd86XSyfILvMUkfkx/DQNij7RWTLJLcx8D449i26o+ENiDgw1DeGz4ERe X-Received: by 10.101.77.142 with SMTP id p14mr12892353pgq.106.1520266952251; Mon, 05 Mar 2018 08:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266952; cv=none; d=google.com; s=arc-20160816; b=QxE7trcClCo80qikjScnpf4rvu6S4HlXteNQXdrt5qM//R2v55CVJiNrjKAzLA9IVL dmeR3scgdhaibLa+hXz6wru0oAQZkt0/+VG6l0+OWAV/pL+WANGOa61yCafnkmcfRpb3 01/CwV2W2MyLchbirsPldnKIVyOTQ1AzkALnpZ1ZlaoBaV4v1pXh2OQ1g2CrRjxmkj+L kfBb0MVYzzyzPM2eh2kQfDlwX60dCZLVOhu5qby7i6nBa+zLngYCABiSIMBYx/20eqN0 M3Gm1Gz3omJyrVL3mNqBTnIdUX+pyUrFqlaCIjZ7I2o9ZPrbo53kw+kEf97YME1hLpR4 +q+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:arc-authentication-results; bh=4OYjRmsr7Mt9SduEw95siK1PcWemtPkor4OSzjYlAmo=; b=eb/fe1vFqQ1rdaKDgL+U754nwlmGlLP7Fh9d3v5XKltIwaRQHdmG+jGrhoiyXj5eVL 2QDOnavFKSIgJVKYmlD7fdcWAQbcHJlPcN8PE9LgkHo5q/Vrr7gfAfqPt0jKqreZkV2p I2f1UyzT31LuGMwhBhZdXjyrr2ZnLtgOr0KT0QmLLd6pvOxZ72xHoxy++7e9lVKL1gif vohA4NIq1G8W58RBb5o+cLa9VoSE56xECDtf39xhqQFIpMKQOwW/IFs4Fd3PhvXX0JWQ wpUGEnnLHqUnI0H/Ln1A7gZCt9mWvTV6yCdL1wOsmEyCUDwLT/CUOcQxUksAqhd5DEWk H9Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n27si10483404pfg.102.2018.03.05.08.22.18; Mon, 05 Mar 2018 08:22:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932215AbeCEQU7 (ORCPT + 99 others); Mon, 5 Mar 2018 11:20:59 -0500 Received: from mout.web.de ([212.227.17.12]:37021 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751471AbeCEQU6 (ORCPT ); Mon, 5 Mar 2018 11:20:58 -0500 Received: from [192.168.1.2] ([92.228.188.109]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M09dQ-1eY2cY0HZE-00uLEU; Mon, 05 Mar 2018 17:20:50 +0100 Subject: [PATCH 1/2] VMCI: Use memdup_user() rather than duplicating its implementation From: SF Markus Elfring To: kernel-janitors@vger.kernel.org, Al Viro , Arnd Bergmann , Greg Kroah-Hartman , George Zhang Cc: LKML , Andy King , Dmitry Torokhov References: <66411a1a-fd12-dc31-fc2e-800ff6cea1ed@users.sourceforge.net> Message-ID: <7c97d2aa-7d3e-468f-cdb7-795a50d437c3@users.sourceforge.net> Date: Mon, 5 Mar 2018 17:20:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <66411a1a-fd12-dc31-fc2e-800ff6cea1ed@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:vy/sL+e5n2BdprGyMMTAp+F1/1y5tLRXUYck/cyDrP43DH8LJNf sQfEVe9kzpcgLr7onn8DEsuCvNvuS/hPSvcNVGqL0LQ+KKrzrcTKMOTOa/Bt1Z2wJNvM89O RzywKSLE465HaH1TofKfb/ttg8Z+ZgId1vdQfvtwbxySlO68QIhKXgTqkytVBZaBwPo1ASb 0G5pQXtQ9LSxctTVOhNBg== X-UI-Out-Filterresults: notjunk:1;V01:K0:pCPJo9/5U6w=:ZgmDoyrBejftz+wrnJywhH KpeVAtaFgmRMOrsrRl+PRd1osIrYxJNod1bVyQ1yMHsHmMR0MpVEyMGBpQB+pH820thVwmvzD GB9/oljbXse0mx+chTKfQLkE8sNdEgJVSw/yZs3aCsnEQB2P7N5scvWJEHBWUfyujHih8ROOx aVXUxcoZk9HlK3AqwWbw1wiA5RVFUMi5BbgSOu4c8BcyFfxNBJvTopraOUH8b3xmAn9YTAimC fl9Ubqwaj0hkMKNB3NGzvX7Uo4ZtN5r1LiYz4OuL1AhfXYIAi8gPbo0xxFEK8/WAp5IrOge2P Ehxj6MsMDJ4Lnu3H4GwyPTGJi5jPzmACl85RMzLbelqhTGu0kB3qcY4UI48QMoOW7ps+3BTk1 yMXQyiY9qX09mA+beWdmwXdS4wymXjt3WQq/Ii15VPci2WcCPZIm0cHJ/DHVCugzNgHwDFgAk X3FhAkYZWMjdcecmwdKyRQTqW6IMSVM6cli12M/5KkVyJuSS1xOrpBt398CU8wLsMCWEntUcv P46mr50kxFtr54oioWt9pLsYd/fG/bh6lstb4vClci40dejobSg4sByt88FW+GVuD+asAehG/ oiZL8HcNI2jjHvZ2BR37SpdxYtIxx09iKf1eoeE6nzfM0Ex35+u9WXhibrv96N7duwIQuRPAx XakQQhMDG+43dy+jpmqSxFcIrn9K5Tf+SDHSM9dLrxXsNVZqLAqDmCrNlv8ww/B53gdXu8V6g /mzkKz7lyxiBK5iDhJPdr7pEL59x/kW6f/dfqUmerJxhECFOqk5lBfvNs7vO0SailhyDq2h5v ToQ32xd0vSkdKaCNtHW2ZTrxqIhNHnFYmRKUGEdJfjvJSk7NnM= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Mon, 5 Mar 2018 16:40:29 +0100 * Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. * Return directly after this function call failed at the beginning. * Delete the label "out" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/misc/vmw_vmci/vmci_host.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c index 83e0c95d20a4..fb3d92a21afa 100644 --- a/drivers/misc/vmw_vmci/vmci_host.c +++ b/drivers/misc/vmw_vmci/vmci_host.c @@ -754,27 +754,16 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev, if (copy_from_user(&set_info, uptr, sizeof(set_info))) return -EFAULT; - cpt_buf = kmalloc(set_info.buf_size, GFP_KERNEL); - if (!cpt_buf) { - vmci_ioctl_err( - "cannot allocate memory to set cpt state (type=%d)\n", - set_info.cpt_type); - return -ENOMEM; - } - - if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf, - set_info.buf_size)) { - retval = -EFAULT; - goto out; - } + cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf, + set_info.buf_size); + if (IS_ERR(cpt_buf)) + return PTR_ERR(cpt_buf); cid = vmci_ctx_get_id(vmci_host_dev->context); set_info.result = vmci_ctx_set_chkpt_state(cid, set_info.cpt_type, set_info.buf_size, cpt_buf); retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0; - -out: kfree(cpt_buf); return retval; } -- 2.16.2