Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp771550pxk; Wed, 9 Sep 2020 19:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyvNK61LwJlCUOrIerFw2TUMJayAXAdRCBfqvFGnVX68sN16tOs8f4ImHssuQMzKyoNpLj X-Received: by 2002:a50:fb15:: with SMTP id d21mr7525294edq.150.1599706626188; Wed, 09 Sep 2020 19:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599706626; cv=none; d=google.com; s=arc-20160816; b=ngfY4hacR2NU/1AOZ1xEU+FxuI1SN9+AbtY0e+8dh3Ik50shphEPIzHQROKQhAACFU DL4GiCvwBhNVyIM5Stlz9SYpRo6ioE70dG3bqb2HiAp4/gpbNT6VdjG7R8PZ11T34V8h dDOjnZ24bPLCfyZddFNnOu6QVUOfoUFQtE973+yl+zRpJRyNUOQw4ut4WeoIuqctIdEV UrXriApmzOaZx+4ATM5SZgnMO9JoQ9ZLBeGqMKmUzH1Q5yvmhkKHV/HFcQUDlHG8Bw9n symsFvmqjGqA0whB4AmH1PoOmXnbfAyrgiOCPOt8ed+BlrqcXej9Rr50Ec8YjLQFvNRn gDRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=0C1QtHwLo5ZP+Ar8+ErpMK60qaWJInbsQRohKM7A1QA=; b=yXebHzzyX8lCkSPSdqaHR3LIFEKBAqgpYqevDr8VA/2ajyZSv2ScKdFVthC5FTbl2d kkABNk6BNG3JXyO8UURUOP38sgKvXv50hL00xCuHxzlEPp6MOj+nX16sgtdoPea5gDTE VJ6lhQMzZ2L1p+93/SObGyLA8md3cabcXNP7QmiqRC/x/I1kCT8ccc0lho5RFOZ275EN NvqMi/Uhopwm184SB5F8DWrXyRqvJVx+LM/E+iUg+HeljFtZvAz2P06ETRuq+FngRsTY g+72VTjWSEYJYFMs+chc4GFBvcuaXV0ob1+iwBdYWKRjzEc3tlVyXZBZBCG5wAG4x276 3zig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b4zjHySO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x90si2610060edc.81.2020.09.09.19.56.43; Wed, 09 Sep 2020 19:57:06 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b4zjHySO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730082AbgIJCyK (ORCPT + 99 others); Wed, 9 Sep 2020 22:54:10 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:49051 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730193AbgIJB4h (ORCPT ); Wed, 9 Sep 2020 21:56:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599702992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0C1QtHwLo5ZP+Ar8+ErpMK60qaWJInbsQRohKM7A1QA=; b=b4zjHySOiKU+WfwFqg08c1d546JSHBRhPhv+QR5crm4IZB0Htw/xPiVmSilit8D//rG9/R 6kmt0Ju/ZkRJwpY9A2BZ6yhxwtcSGE1hU8R5Zdf7gr0vgO4hEFeKxXCvkxLtHyZaK0yctQ c5gPBfQ8FXS6w77GRJJPPAk7PUCqA3o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-ZMZwJTTFNGOE9gvdtSDulw-1; Wed, 09 Sep 2020 21:56:28 -0400 X-MC-Unique: ZMZwJTTFNGOE9gvdtSDulw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9D6F593B2; Thu, 10 Sep 2020 01:56:24 +0000 (UTC) Received: from [10.72.13.124] (ovpn-13-124.pek2.redhat.com [10.72.13.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0B3B60BF1; Thu, 10 Sep 2020 01:56:06 +0000 (UTC) Subject: Re: [PATCH] vhost-vdpa: fix memory leak in error path To: Li Qiang , mst@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: Jason Wang Message-ID: Date: Thu, 10 Sep 2020 09:56:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200909154120.363209-1-liq3ea@163.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/9/9 下午11:41, 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; > } Cc: stable@vger.kernel.org Acked-by: Jason Wang