Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp9559pxk; Wed, 23 Sep 2020 20:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvRrFhv6lxFklqezm5efkatTEAW5p6aSIE9XMx39ZftFkU9PKMMTPuVfUMjlBDD25VgmGP X-Received: by 2002:a17:906:aecb:: with SMTP id me11mr2677707ejb.217.1600917851631; Wed, 23 Sep 2020 20:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600917851; cv=none; d=google.com; s=arc-20160816; b=C+NqfJqoEbn7LFoUa7cdK9lpaiHqbUoDI5iYJ8USEqUp4AHZMQbdYfNeSdzDTah2AS 0+6pzOkxq9iEC5nGbUVl3ym5nXCRFKQq4bsZVBag4+RB/jPnTapF/nxnrtPCEBJ/FMAw aQcW+O2jyA02u9ukqu9HfcAw71IHg3zn4gSY6bUM5N/j4qSf8OnMmSCaUa0OpqPBKBfc 69NuIbOucqfI5M/GJizPBwDpO/xDjPzWS5rLO2g2eU2+FxiYFVbRMvALejd7FqvMVpVi TNJ0L1TJokpDSIgbS/1Pap9exFZcAzcdeaLg5LOtA/F7x9QQU6SnJcf98eTFIDQL6XNU igxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yL5gnmJjXM50BmL15PZqm3Qryv26tfuJ/8EBJBgWRs8=; b=0MkTLoJHx5rYbdIDs1EB7elbpskLGM17TFMz43QN7vjJM6QcBNky1kUjaUURxYupYX B5y3Ha/IBq0SyjOMmYaJs8hGNY+QK2mU3muPrsjz4LkvlxkriTif2AutnfsoamUUz8DJ fAzjn08tAzkVCBt05Cs0fBx02/nlNox0j1ChrxgAiGwbyM/Jw8Vu5m6oFKOxuMJVnHxu dPrzhsrix4DOTLYSWFLdEoAnV2npF6YLVDqDkxgYpLyYFMp2bKEuUmgefiZNyfUe+9O/ WFj3V2mm37r8FOnEwved48EB8gR/BNY9BzEHs47v8UXCYvOv4qeu+knfRvlPFyKGjLVW fUdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZoaSq8Nh; 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 l24si1255883eji.478.2020.09.23.20.23.47; Wed, 23 Sep 2020 20:24:11 -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=ZoaSq8Nh; 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 S1726699AbgIXDWM (ORCPT + 99 others); Wed, 23 Sep 2020 23:22:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27377 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbgIXDWM (ORCPT ); Wed, 23 Sep 2020 23:22:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600917731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yL5gnmJjXM50BmL15PZqm3Qryv26tfuJ/8EBJBgWRs8=; b=ZoaSq8Nh60hWkXdR9MnzuXQX1s3ck+W+0tl6lsRV6oxU8xA1IZdVPfzqqs0s22BvCzd1WV qxi9BZvgjQKgUFoMt4ZA4Nj5RHC20XQAJDGRamgaQPEpC2SBTpkxn2LkR/uivilyYKHxfG GwL5ieXO7LxytZD8eccO0oJNTI5oHn0= 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-204-3to2PfkSM_eUuEe1qWyNBA-1; Wed, 23 Sep 2020 23:22:09 -0400 X-MC-Unique: 3to2PfkSM_eUuEe1qWyNBA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2008F1074652; Thu, 24 Sep 2020 03:22:06 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-13-193.pek2.redhat.com [10.72.13.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA91355768; Thu, 24 Sep 2020 03:21:50 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: lulu@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rob.miller@broadcom.com, lingshan.zhu@intel.com, eperezma@redhat.com, hanand@xilinx.com, mhabets@solarflare.com, eli@mellanox.com, amorenoz@redhat.com, maxime.coquelin@redhat.com, stefanha@redhat.com, sgarzare@redhat.com Subject: [RFC PATCH 02/24] vhost-vdpa: fix vqs leak in vhost_vdpa_open() Date: Thu, 24 Sep 2020 11:21:03 +0800 Message-Id: <20200924032125.18619-3-jasowang@redhat.com> In-Reply-To: <20200924032125.18619-1-jasowang@redhat.com> References: <20200924032125.18619-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); +} + 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