Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1182719pxk; Fri, 18 Sep 2020 06:07:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBxcXe5lEsxO3Cq4Xz0LjeQqK8oa9uBw7VERM2nG0uwyD8w51KIsSu0wao2iEGbAGBxUoW X-Received: by 2002:a17:907:64d:: with SMTP id wq13mr35098050ejb.513.1600434470708; Fri, 18 Sep 2020 06:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600434470; cv=none; d=google.com; s=arc-20160816; b=kfDEjgoReQIdD7ece6AyFKaN0ZFGQOUp8N8DOsB1VK7EKY5Y/YCRPAHC86ZZ8ewa/g 6fGGF/wBR19F/S8Obax7/R5AWqNMz4ZiPFBLK0pOAUa0Sq1VNv5PPkFM+CRZU4YIlD02 v6KcpobwDPhAOwKXYGEH5bif+7PWdnfGqBavVd1/P+lj4BEKkOk9ck8TRlqOac0VwquX iNiJXlgqasaeGC9cYBDF3zK1n2A63CFwvVQ2I6oLyS+CgQr+Zwq6UVhrhmHqR8nTjOsZ c3nJmi4FOaiPGOkZ1ZNFai7OrCi/zh5QjVaYKwQfj/KOS/JUsYwoOkgG4XDiyTCQ35OB 5CNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=GnrZC9PfbxJ996/fSdBhbePanr03ziqhsLOfnwes5Rs=; b=J38rIPgiHCtuo6cNw7/R0z2blSHEEhJchfFMKx3bipP2DyFFDyhENIVmRSlBqoGf7l a0Ijf8oJv8CP1m6w5KUZB7lfXEzQLQDsjGO0QOuGwTYegLIc8QOFH2cx1tVk0TklHk8o V+824E1R+vV2bqB6sI8u1p8x/n4t/faHsGzu4BOwYT8o18V9kAyYxXkFQZ40tes3h+1A eSYnGkrTpQsnptzGWusgYjB0HemVsepifvwPbXJ3NsmBiTgli3JNXSK1d09OXvT6WTNP CfliO9TeEg1IzLlPoSJH1mKZ0Fim0iz7UCmIyXyYr4mXuf3VxJckQ5nFi0Qxp1moH+1u g6Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s24si2142554edr.379.2020.09.18.06.07.26; Fri, 18 Sep 2020 06:07:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbgIRNDv (ORCPT + 99 others); Fri, 18 Sep 2020 09:03:51 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:43361 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgIRNDu (ORCPT ); Fri, 18 Sep 2020 09:03:50 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R351e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0U9JntaJ_1600434225; Received: from B-455UMD6M-2027.local(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0U9JntaJ_1600434225) by smtp.aliyun-inc.com(127.0.0.1); Fri, 18 Sep 2020 21:03:46 +0800 Subject: Re: [PATCH] vhost-vdpa: fix memory leak in error path To: Li Qiang , mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, liq3ea@gmail.com References: <20200909154120.363209-1-liq3ea@163.com> From: Tianjia Zhang Message-ID: <1104febd-1f2d-5edd-52e9-ca992e6d5340@linux.alibaba.com> Date: Fri, 18 Sep 2020 21:03:45 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: <20200909154120.363209-1-liq3ea@163.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LGTM. Reviewed-by: Tianjia Zhang Thanks. On 9/9/20 11:41 PM, Li Qiang wrote: > Free the 'page_list' when the 'npages' is zero. > > Signed-off-by: Li Qiang > --- > drivers/vhost/vdpa.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index 3fab94f88894..6a9fcaf1831d 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c > @@ -609,8 +609,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, > gup_flags |= FOLL_WRITE; > > npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT; > - if (!npages) > - return -EINVAL; > + if (!npages) { > + ret = -EINVAL; > + goto free_page; > + } > > mmap_read_lock(dev->mm); > > @@ -666,6 +668,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, > atomic64_sub(npages, &dev->mm->pinned_vm); > } > mmap_read_unlock(dev->mm); > + > +free_page: > free_page((unsigned long)page_list); > return ret; > } >