vfio: fix noiommu vfio_iommu_group_get reference count
authorEric Auger <eric.auger@redhat.com>
Fri, 11 Aug 2017 13:16:06 +0000 (15:16 +0200)
committerAlex Williamson <alex.williamson@redhat.com>
Wed, 30 Aug 2017 20:00:47 +0000 (14:00 -0600)
In vfio_iommu_group_get() we want to increase the reference
count of the iommu group.

In noiommu case, the group does not exist and is allocated.
iommu_group_add_device() increases the group ref count. However we
then call iommu_group_put() which decrements it.

This leads to a "refcount_t: underflow WARN_ON".

Only decrement the ref count in case of iommu_group_add_device
failure.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c

index 330d50582f400e7cd93d3242d91270e0d1fdbf66..4ee4f361fe9fc32b1a68aabe362cd459c5ccabf1 100644 (file)
@@ -138,9 +138,10 @@ struct iommu_group *vfio_iommu_group_get(struct device *dev)
        iommu_group_set_name(group, "vfio-noiommu");
        iommu_group_set_iommudata(group, &noiommu, NULL);
        ret = iommu_group_add_device(group, dev);
-       iommu_group_put(group);
-       if (ret)
+       if (ret) {
+               iommu_group_put(group);
                return NULL;
+       }
 
        /*
         * Where to taint?  At this point we've added an IOMMU group for a