From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6526FC433F5 for ; Wed, 13 Oct 2021 16:09:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A17D610C9 for ; Wed, 13 Oct 2021 16:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234305AbhJMQLQ (ORCPT ); Wed, 13 Oct 2021 12:11:16 -0400 Received: from verein.lst.de ([213.95.11.211]:46437 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhJMQLQ (ORCPT ); Wed, 13 Oct 2021 12:11:16 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id E5B8F68B05; Wed, 13 Oct 2021 18:09:10 +0200 (CEST) Date: Wed, 13 Oct 2021 18:09:10 +0200 From: Christoph Hellwig To: Jason Gunthorpe Cc: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Christoph Hellwig , "Tian, Kevin" , Liu Yi L Subject: Re: [PATCH v2 3/5] vfio: Don't leak a group reference if the group already exists Message-ID: <20211013160910.GC1327@lst.de> References: <0-v2-fd9627d27b2b+26c-vfio_group_cdev_jgg@nvidia.com> <3-v2-fd9627d27b2b+26c-vfio_group_cdev_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3-v2-fd9627d27b2b+26c-vfio_group_cdev_jgg@nvidia.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org > @@ -775,12 +776,7 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev) > if (group) > goto out_put; > > - /* a newly created vfio_group keeps the reference. */ > group = vfio_create_group(iommu_group, VFIO_IOMMU); > - if (IS_ERR(group)) > - goto out_put; > - return group; > - > out_put: > iommu_group_put(iommu_group); > return group; I'd simplify this down to: group = vfio_group_get_from_iommu(iommu_group); if (!group) group = vfio_create_group(iommu_group, VFIO_IOMMU); but otherwise this looks good: Reviewed-by: Christoph Hellwig