From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751570AbdKVPzr (ORCPT ); Wed, 22 Nov 2017 10:55:47 -0500 Received: from smtprelay0198.hostedemail.com ([216.40.44.198]:40260 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751259AbdKVPzq (ORCPT ); Wed, 22 Nov 2017 10:55:46 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:966:968:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2828:2899:3138:3139:3140:3141:3142:3352:3622:3865:3867:3868:3871:4031:4321:4385:4419:5007:6119:6997:7903:10004:10400:10848:11026:11232:11658:11914:12043:12296:12438:12679:12740:12760:12895:13069:13161:13229:13311:13357:13439:14659:14721:21080:21451:21627:30045:30051:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: fan78_14e06dc55e442 X-Filterd-Recvd-Size: 2021 Message-ID: <1511366141.6989.89.camel@perches.com> Subject: Re: [PATCH] VMCI: Use memdup_user() as a cleanup From: Joe Perches To: Vasyl Gomonovych , mingo@kernel.org Cc: linux-kernel@vger.kernel.org Date: Wed, 22 Nov 2017 07:55:41 -0800 In-Reply-To: <1511364547-18418-1-git-send-email-gomonovych@gmail.com> References: <1511364547-18418-1-git-send-email-gomonovych@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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;