فهرست منبع

vfio: put off the allocation of "minor" in vfio_create_group

The next code fragment "list_for_each_entry" is not depend on "minor". With this
patch, the free of "minor" in "list_for_each_entry" can be reduced, and there is
no functional change.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Zhen Lei 10 سال پیش
والد
کامیت
2f51bf4be9
1فایلهای تغییر یافته به همراه6 افزوده شده و 7 حذف شده
  1. 6 7
      drivers/vfio/vfio.c

+ 6 - 7
drivers/vfio/vfio.c

@@ -234,22 +234,21 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group)
 
 
 	mutex_lock(&vfio.group_lock);
 	mutex_lock(&vfio.group_lock);
 
 
-	minor = vfio_alloc_group_minor(group);
-	if (minor < 0) {
-		vfio_group_unlock_and_free(group);
-		return ERR_PTR(minor);
-	}
-
 	/* Did we race creating this group? */
 	/* Did we race creating this group? */
 	list_for_each_entry(tmp, &vfio.group_list, vfio_next) {
 	list_for_each_entry(tmp, &vfio.group_list, vfio_next) {
 		if (tmp->iommu_group == iommu_group) {
 		if (tmp->iommu_group == iommu_group) {
 			vfio_group_get(tmp);
 			vfio_group_get(tmp);
-			vfio_free_group_minor(minor);
 			vfio_group_unlock_and_free(group);
 			vfio_group_unlock_and_free(group);
 			return tmp;
 			return tmp;
 		}
 		}
 	}
 	}
 
 
+	minor = vfio_alloc_group_minor(group);
+	if (minor < 0) {
+		vfio_group_unlock_and_free(group);
+		return ERR_PTR(minor);
+	}
+
 	dev = device_create(vfio.class, NULL,
 	dev = device_create(vfio.class, NULL,
 			    MKDEV(MAJOR(vfio.group_devt), minor),
 			    MKDEV(MAJOR(vfio.group_devt), minor),
 			    group, "%d", iommu_group_id(iommu_group));
 			    group, "%d", iommu_group_id(iommu_group));