Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751902AbcKBLhu (ORCPT ); Wed, 2 Nov 2016 07:37:50 -0400 Received: from mga05.intel.com ([192.55.52.43]:8305 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbcKBLht (ORCPT ); Wed, 2 Nov 2016 07:37:49 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,583,1473145200"; d="scan'208";a="26551170" Message-ID: <5819CF3E.9060304@intel.com> Date: Wed, 02 Nov 2016 19:34:22 +0800 From: Jike Song User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Kirti Wankhede CC: alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 04/19] vfio: Common function to increment container_users References: <1477517366-27871-1-git-send-email-kwankhede@nvidia.com> <1477517366-27871-5-git-send-email-kwankhede@nvidia.com> In-Reply-To: <1477517366-27871-5-git-send-email-kwankhede@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2124 Lines: 76 On 10/27/2016 05:29 AM, Kirti Wankhede wrote: > This change rearrange functions to have common function to increment > container_users > > Signed-off-by: Kirti Wankhede > Signed-off-by: Neo Jia > Change-Id: I8bdeb352bc8439b107ffd519480fd4dc238677f2 > --- > drivers/vfio/vfio.c | 34 +++++++++++++++++++++------------- > 1 file changed, 21 insertions(+), 13 deletions(-) > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > index 23bc86c1d05d..2e83bdf007fe 100644 > --- a/drivers/vfio/vfio.c > +++ b/drivers/vfio/vfio.c > @@ -1385,6 +1385,23 @@ static bool vfio_group_viable(struct vfio_group *group) > group, vfio_dev_viable) == 0); > } > > +static int vfio_group_add_container_user(struct vfio_group *group) > +{ > + if (!atomic_inc_not_zero(&group->container_users)) > + return -EINVAL; > + > + if (group->noiommu) { > + atomic_dec(&group->container_users); > + return -EPERM; > + } trivial: a blank line here > + if (!group->container->iommu_driver || !vfio_group_viable(group)) { > + atomic_dec(&group->container_users); > + return -EINVAL; > + } > + > + return 0; > +} > + > static const struct file_operations vfio_device_fops; > > static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) > @@ -1694,23 +1711,14 @@ static const struct file_operations vfio_device_fops = { > struct vfio_group *vfio_group_get_external_user(struct file *filep) > { > struct vfio_group *group = filep->private_data; > + int ret; > > if (filep->f_op != &vfio_group_fops) > return ERR_PTR(-EINVAL); > > - if (!atomic_inc_not_zero(&group->container_users)) > - return ERR_PTR(-EINVAL); > - > - if (group->noiommu) { > - atomic_dec(&group->container_users); > - return ERR_PTR(-EPERM); > - } > - > - if (!group->container->iommu_driver || > - !vfio_group_viable(group)) { > - atomic_dec(&group->container_users); > - return ERR_PTR(-EINVAL); > - } > + ret = vfio_group_add_container_user(group); > + if (ret) > + return ERR_PTR(ret); > > vfio_group_get(group); > Reviewed-by: Jike Song -- Thanks, Jike