Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp120372pxk; Thu, 24 Sep 2020 00:50:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGIFHRs7Ha0WD2ZIJ92c15kYKbPe6LZOdz5qc1pal1IbfjnsizQWYIVAO87CTKVuy0cC/S X-Received: by 2002:a50:8e58:: with SMTP id 24mr3391747edx.226.1600933853949; Thu, 24 Sep 2020 00:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600933853; cv=none; d=google.com; s=arc-20160816; b=nLvDgPlWUgXNDJ5w4TpK4Lz60zMRZSnTbGPXJKNKgZR+VpymhJ2HWL61vHtYdGkRil 5xo84fuhxpi7r+iO77cIX6oFiX3z1VpPVnHLeVYVEHwWg0GHauWiZeWpsWG6hNs5Mbx3 NifEeAmstLWwTB37H+wn2nbyrMB2tD9/DVctBbRfHllFa6TaDrieqo/xlciQktrC8G0A JgPsEWo8pkCJOOIKLZryA4Ypxr/ov/hlVXpq+64S1U6BJcqmGzngCXqJFiEB55dCYCBJ NuZxlmCE0wpb9G074IF/XUtmWRJZN2v9ilYRaaTbyzduts576HeQoKPzqvO9EZ/nOnRl dQZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rNTNNkETGhPd0luFzWcBZwK95dJtpJNa49ZvIYcU5ac=; b=I7KMNWh2NDNZpx6p3pw9cowecM5f7CKZHHMPbdeh7rOfge9HppxjV0nv5wM+7srT+j 4B6EyOzNjPJ7Jufx25YKngVE4WFc09BoDuyPfSGuWtWb2DYZcQMrXI5NtJMAe+kkaFXf O6vuHJVIOZBRBtf6j1Vl5wyGdv1JOhvF9690M4onebpXSI9c/CenxfYAxT3wd488IehH IROXZHXxcPNz1/4BCM2JBa6/5th5OUq6cNFeBc6VxOsAI94aUY/27lIVliGqXmfcHxM/ gJiDTVh4uHCcMVupfUh55WRb84BAOT/t7mwBCBpVRYEFY3h0Xq0X+7+A4Msq+7QWmrsU cARA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=hVgjlZ6o; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si1775079edr.327.2020.09.24.00.50.29; Thu, 24 Sep 2020 00:50:53 -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=@nvidia.com header.s=n1 header.b=hVgjlZ6o; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbgIXHso (ORCPT + 99 others); Thu, 24 Sep 2020 03:48:44 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:19035 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727109AbgIXHso (ORCPT ); Thu, 24 Sep 2020 03:48:44 -0400 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 24 Sep 2020 00:47:09 -0700 Received: from mtl-vdi-166.wap.labs.mlnx (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 24 Sep 2020 07:48:20 +0000 Date: Thu, 24 Sep 2020 10:48:16 +0300 From: Eli Cohen To: Jason Wang CC: , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH 02/24] vhost-vdpa: fix vqs leak in vhost_vdpa_open() Message-ID: <20200924074816.GC170403@mtl-vdi-166.wap.labs.mlnx> References: <20200924032125.18619-1-jasowang@redhat.com> <20200924032125.18619-3-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200924032125.18619-3-jasowang@redhat.com> User-Agent: Mutt/1.9.5 (bf161cf53efb) (2018-04-13) X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1600933629; bh=rNTNNkETGhPd0luFzWcBZwK95dJtpJNa49ZvIYcU5ac=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: X-Originating-IP:X-ClientProxiedBy; b=hVgjlZ6oPWtli0dvdp+IUdd+m1SU/fPaCMDO78V1mbNMd3gr4cXF4WQ3+W31lUrcv yGISMw3YZTGVgn0v4Q22mmb2OFE0EkhgPd9/balo7MUdky2h1L0KaGqLM6G5Z0LpfK EYHlPpytHc6F4koOdryNIEZjF4cLnIoAugNP7BLvwq8cIk7L2yAUs5cx5CkfpGv/lW s7I+N/r/954oV01jW6v++Fbn5/LAx8D2048aF64dBi61axKko9X0aX/LTeKycmL1en nTY7k9GhV3S9rZjyQNKhg7idusXUiwGF965aa9GQTHlkvPh9WCWOQvpG/9knvZe4XB G84YAXHAqTulg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24, 2020 at 11:21:03AM +0800, Jason Wang wrote: > We need to free vqs during the err path after it has been allocated > since vhost won't do that for us. > > Signed-off-by: Jason Wang > --- > drivers/vhost/vdpa.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index 796fe979f997..9c641274b9f3 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c > @@ -764,6 +764,12 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v) > v->domain = NULL; > } > > +static void vhost_vdpa_cleanup(struct vhost_vdpa *v) > +{ > + vhost_dev_cleanup(&v->vdev); > + kfree(v->vdev.vqs); > +} > + Wouldn't it be cleaner to call kfree(vqs) explicilty inside vhost_vdpa_open() in case of failure and keep the symetry of vhost_dev_init()/vhost_dev_cleanup()? > static int vhost_vdpa_open(struct inode *inode, struct file *filep) > { > struct vhost_vdpa *v; > @@ -809,7 +815,7 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) > return 0; > > err_init_iotlb: > - vhost_dev_cleanup(&v->vdev); > + vhost_vdpa_cleanup(v); > err: > atomic_dec(&v->opened); > return r; > @@ -840,8 +846,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep) > vhost_vdpa_free_domain(v); > vhost_vdpa_config_put(v); > vhost_vdpa_clean_irq(v); > - vhost_dev_cleanup(&v->vdev); > - kfree(v->vdev.vqs); > + vhost_vdpa_cleanup(v); > mutex_unlock(&d->mutex); > > atomic_dec(&v->opened); > -- > 2.20.1 >