Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp431379pxk; Wed, 9 Sep 2020 09:01:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxda0hJEY9YkbtBQBVwgOtbxQ456TL0ALfCtO2qfOZna577s4RuQh7qbfyIN2wBG6/zhsVQ X-Received: by 2002:a17:906:1b:: with SMTP id 27mr4232116eja.169.1599667318313; Wed, 09 Sep 2020 09:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599667318; cv=none; d=google.com; s=arc-20160816; b=vC60U+dy1pDbu8y+PtfiFc9qFmPMvpYxlz5JKQdpZS5f5dXK17lSddH7ZkfYBjmY4S A7IBw9sfTPi2Jvwk5vfnMYepvmfCPOfC7Wn/Wozlzrox4n5fvwDrpfUVMhK3V6Xud6vE CAiZEKaU9esi7wgkn1mOUq+J4cxyay6u4gHGZkPeBvcV30Tj6axZ7L1VLSpCAa8mun7/ rjCw5mBsxQD+Yq7AXwcXp/Xgd5WANFA1y7yqZl+1pd2KYKZMpZ1xnPC6NqoGLR8svP2a sWWTU+JGH8xRSepjX7m998I3M74rZbByIHpqoh4KjbyKuPxGjiF+gX0oVtpAAvczweBT P4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=uwS0BZkJxp7aqJXVSsXep+7iwuK+EfIF9+hccxzGrAk=; b=SB2OYPxLLhhoWPPkoef6ZXTSjvL+7+CP7KZhotBSGYii7okgoTg90MOtH2WZedxlIw 7DWUoREXuz2b9pho9iTZHXKt1gv7sGGpQLWzbyhRDV2OYK75vGugtB+Nt3Ve6nrN8R0E Xk2+WqIaUuNsEIH3SLrmZ21v1GkSoivXfCHg5c1EdyyvGdZ+qScvc90b+zyigBhMbtIp zcMUoUbjTf70jmluMfvMzBALo4mhy+mJ8mm3fnfr9S+Ka/8qVCYuCGdbH9sCfxxX2WHd UEC0FtuOl6Lp3h+5C6qhbM7Ef0ovFfHHUrt0BfLq7YcXTMUjUVB5iMKr6Z3cxjVJCOf/ aW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=o0bNKeWG; 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=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p2si1688897ejf.310.2020.09.09.09.01.31; Wed, 09 Sep 2020 09:01:58 -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=@163.com header.s=s110527 header.b=o0bNKeWG; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730716AbgIIP7n (ORCPT + 99 others); Wed, 9 Sep 2020 11:59:43 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:51034 "EHLO mail-m975.mail.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730577AbgIIP6l (ORCPT ); Wed, 9 Sep 2020 11:58:41 -0400 X-Greylist: delayed 965 seconds by postgrey-1.27 at vger.kernel.org; Wed, 09 Sep 2020 11:58:05 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=uwS0B ZkJxp7aqJXVSsXep+7iwuK+EfIF9+hccxzGrAk=; b=o0bNKeWGTJfkaOxtSEh1D +GzlLtBIscb9UKl7SP608fxmKv0nZrQj+Oi54aEY9UpoEf7mYdqKfX3sX5mtV98m 9hyFvY1qoKiTO+LyzvclhewoOZLDuXZkV9nOaXuI4hALSFpOUYPIumz1stLulSOu spaq7Nb9nUpWM0nrcRdSOE= Received: from ubuntu.localdomain (unknown [183.158.94.209]) by smtp5 (Coremail) with SMTP id HdxpCgA3yCCm91hfB2vFJw--.5S4; Wed, 09 Sep 2020 23:41:27 +0800 (CST) From: Li Qiang To: 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, Li Qiang Subject: [PATCH] vhost-vdpa: fix memory leak in error path Date: Wed, 9 Sep 2020 08:41:20 -0700 Message-Id: <20200909154120.363209-1-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HdxpCgA3yCCm91hfB2vFJw--.5S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKw48JF1UtFy5uw47WFWxZwb_yoWfCrXE9w 4xurn7JFn3tr4Yv3ZFyw4fAry7KFsru3Z3u3WFkryavF17Z3ZIq3W8ZrnrJw17XrWxGa43 Crn7Cr1I9F1ftjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRRIztUUUUUU== X-Originating-IP: [183.158.94.209] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBLweabVUMN-fMFgAAsc Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.25.1