Received: by 10.223.164.202 with SMTP id h10csp308576wrb; Wed, 22 Nov 2017 07:32:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMYK3CEx/eSZdyDLvtpjJL8tA7+h6SFvIU9ZsIZXEZa+JHucRc9Zzi39p5F6OJ0qsQ/JGYmt X-Received: by 10.99.127.25 with SMTP id a25mr20765370pgd.10.1511364730877; Wed, 22 Nov 2017 07:32:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511364730; cv=none; d=google.com; s=arc-20160816; b=j1Y8WmmR00FH1FKwLXBAuVNK8vVUiHZS2x6lrAH1VM3TN04TIl/ToJ716SEhUy1+V7 bdxPvJmOZtLc5UFxX+zpwntjFh8Q/1+sEcox8LVE0Na5TcAwTwD2HDYWd2nKe/6lvevb qunrXKMOU3CS2TJOzNeZcbM4/XYO7GEBG+IRAcng+oZPbcI3g8F9Su9FYVIdPiKIXXVC RtiLAF1shymtSBu3uHvIYVc8D1NklJQEFKVQ3l5WSPpDvY/jE8vKeN+qJ3DzLFNOderY SaHgM/It0maiM4M/3jOm1bzAKRJ056YJnWkO+/XoSjkKSdu+oc0NOhp6phViieSyuyhC cQnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=YGOdbjTaGJmp3uokgLLyaiZPUs9ca2mw7W1KbjS9U2c=; b=DZmVPUdLtooykEuk0pHBXjWTrc0Ws0qJqkjWArKB1DliitbMAc53p/OYC6jZhIhx1E fe/N3NrsXY9C925Bfu1IDkZera+YLJfAclol8C/8dTqiAPrbUimhKLTzmfL2e6MbIQfi bxPH1Z0BZ9fGrFTYPn942PJFtSg9pV2scA/kLfv+q6bHMdtq08yt9hc/ouW2v0tJxc2f wWYh2e1V6n2UJ6dNy9/m8JMOROD64F2IVccinnuVUTgaar/AlY4lwOaWRQSKV3G21vJ3 fvmq3cadmXWwi2bwGafUDAudSoxY2KGPZs2mbOS+tF+QmQa99i2IVz/NnxNWGFJuYXns Bfpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CR4Wmsn2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si13762329plo.24.2017.11.22.07.31.58; Wed, 22 Nov 2017 07:32:10 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CR4Wmsn2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbdKVP3W (ORCPT + 77 others); Wed, 22 Nov 2017 10:29:22 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:41570 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbdKVP3R (ORCPT ); Wed, 22 Nov 2017 10:29:17 -0500 Received: by mail-lf0-f66.google.com with SMTP id f134so18667253lfg.8 for ; Wed, 22 Nov 2017 07:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YGOdbjTaGJmp3uokgLLyaiZPUs9ca2mw7W1KbjS9U2c=; b=CR4Wmsn2jAcobVbKlUImK1OhPnbq8ixMYsN9DcO51RyDHk5ImOygwoPwPKNpblRPUy UG/AX+jgc++kGB8A+8seHHV5ccgW33rnOmwGoaecJmWfmVomHWLCNatlI/fauNau7GU1 sV9tidgT/It+/XNEm3CWK5KT2347brozHSt8FLaxanYte5kGjwNV4wj0UESnc0ww56ZX p5QPHaDc17APmsbQpr1bVxe6jeAjXPy4fBuBULgE5LLn68igJkbHyT+8vjWsniJ9xhxm am/I26eUA/R2SN/f2+l+/dQwUQhSxLTEg/AlWnw0oHQFiq3p8VwpyrBu1dqk+AR/8eOn dSjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=YGOdbjTaGJmp3uokgLLyaiZPUs9ca2mw7W1KbjS9U2c=; b=kMcZpad9e3SWVeIL1Dm2km2qzaFWLCHX35HAb0JBJzTV6Cr8ZzYfP5uia+auEfRfXY QaUKLt0cZqEii7tWoMDINRBBxVNS8qTMnp0JGj3Gdq6luJZQFawSBFFrVE4VkAfNCsv3 pApAKXCQpd8RsM77DBcApXYqEeTt2gFcMf1ejuFmJ5sQ3ysdVsaoicfIizvaJjUqGkjE g0bJ226wukqZzN3ws03VRpUoWtT1LwmebzgjpS7kU+FvNXCyNns+LDKrWb3hoDNKTfKx C/S9uB6KZ+RuRRmlmBwIueTdzh97Gc6hLrgbiDB+z0bLEmvzWi34yFHj0ZWBpimoI8Z6 852Q== X-Gm-Message-State: AJaThX64k9ztG1OXr3FhkoTK5FBMWwSVeuQE34aZ17U4da1j02gsXSLF i745Ns0Xl4cqzPwcAN+aJJQvIRnN X-Received: by 10.46.68.195 with SMTP id b64mr6547436ljf.121.1511364556330; Wed, 22 Nov 2017 07:29:16 -0800 (PST) Received: from localhost.localdomain ([195.254.138.66]) by smtp.gmail.com with ESMTPSA id w7sm3658466ljd.95.2017.11.22.07.29.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Nov 2017 07:29:15 -0800 (PST) From: Vasyl Gomonovych To: mingo@kernel.org Cc: linux-kernel@vger.kernel.org, gomonovych@gmail.com Subject: [PATCH] VMCI: Use memdup_user() as a cleanup Date: Wed, 22 Nov 2017 16:29:07 +0100 Message-Id: <1511364547-18418-1-git-send-email-gomonovych@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix coccicheck warning which recommends to use memdup_user(): drivers/misc/vmw_vmci/vmci_host.c:757:11-18: WARNING opportunity for memdup_user Generated by: scripts/coccinelle/memdup_user/memdup_user.cocci Signed-off-by: Vasyl Gomonovych --- drivers/misc/vmw_vmci/vmci_host.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c index 8a16a26e9658..b8468b864bcd 100644 --- a/drivers/misc/vmw_vmci/vmci_host.c +++ b/drivers/misc/vmw_vmci/vmci_host.c @@ -754,18 +754,12 @@ 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)) { + vmci_ioctl_err("cannot allocate memory to set cpt state (type=%d)\n", + set_info.cpt_type); + return PTR_ERR(cpt_buf); } cid = vmci_ctx_get_id(vmci_host_dev->context); @@ -774,7 +768,6 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev, retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0; -out: kfree(cpt_buf); return retval; } -- 1.9.1 From 1584808256700638107@xxx Wed Nov 22 22:48:50 +0000 2017 X-GM-THRID: 1584807116228487842 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread