From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751515AbdKVUqQ (ORCPT ); Wed, 22 Nov 2017 15:46:16 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:46407 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751324AbdKVUqP (ORCPT ); Wed, 22 Nov 2017 15:46:15 -0500 X-Google-Smtp-Source: AGs4zMaX47qRIn1IZWeV3TeW8Ba57EjmucDdoOs5s5ts5R1DGMhv4K798xPTtf0GwMi94N4IWwi9ZryAeMNhWIifcvQ= MIME-Version: 1.0 In-Reply-To: <1511366141.6989.89.camel@perches.com> References: <1511364547-18418-1-git-send-email-gomonovych@gmail.com> <1511366141.6989.89.camel@perches.com> From: "Gomonovych, Vasyl" Date: Wed, 22 Nov 2017 21:46:14 +0100 Message-ID: Subject: Re: [PATCH] VMCI: Use memdup_user() as a cleanup To: Joe Perches Cc: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vAMKkKLM013773 I am agree, I will change it. On Wed, Nov 22, 2017 at 4:55 PM, Joe Perches wrote: > On Wed, 2017-11-22 at 16:29 +0100, Vasyl Gomonovych wrote: >> 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 > > Nice little cleanup. > >> diff --git 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, > [] >> + 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); > > Trivia: > > The vmci_ioctl_err might not be necessary. > There is a dump_stack() on allocation failure. > > and > >> @@ -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; > > Perhaps move the kfree above the copy_to_user, > remove the retval declaration and use > > return copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0; > -- Доброї вам пори дня.