Merge tag 'drm-for-v4.16-part2-fixes' of git://people.freedesktop.org/~airlied/linux
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / gvt / kvmgt.c
index 801a3375c7b4fcbf6e2d73c261221faa8d565bba..909499b73d03acba1a1af1f6f5b77c7ccdd07b5c 100644 (file)
@@ -1051,6 +1051,8 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
                        if (!sparse)
                                return -ENOMEM;
 
+                       sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
+                       sparse->header.version = 1;
                        sparse->nr_areas = nr_areas;
                        cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
                        sparse->areas[0].offset =
@@ -1076,7 +1078,9 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
                        break;
                default:
                        {
-                               struct vfio_region_info_cap_type cap_type;
+                               struct vfio_region_info_cap_type cap_type = {
+                                       .header.id = VFIO_REGION_INFO_CAP_TYPE,
+                                       .header.version = 1 };
 
                                if (info.index >= VFIO_PCI_NUM_REGIONS +
                                                vgpu->vdev.num_regions)
@@ -1093,8 +1097,8 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
                                cap_type.subtype = vgpu->vdev.region[i].subtype;
 
                                ret = vfio_info_add_capability(&caps,
-                                               VFIO_REGION_INFO_CAP_TYPE,
-                                               &cap_type);
+                                                       &cap_type.header,
+                                                       sizeof(cap_type));
                                if (ret)
                                        return ret;
                        }
@@ -1104,8 +1108,9 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
                        switch (cap_type_id) {
                        case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
                                ret = vfio_info_add_capability(&caps,
-                                       VFIO_REGION_INFO_CAP_SPARSE_MMAP,
-                                       sparse);
+                                       &sparse->header, sizeof(*sparse) +
+                                       (sparse->nr_areas *
+                                               sizeof(*sparse->areas)));
                                kfree(sparse);
                                if (ret)
                                        return ret;