From: Jonathan Cavitt Date: Thu, 18 Sep 2025 21:45:16 +0000 (+0000) Subject: drm/i915/gvt: Simplify case switch in intel_vgpu_ioctl X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69b4d367fff6d311da6e3ce1b8b34b3e37b59b5a;p=thirdparty%2Fkernel%2Flinux.git drm/i915/gvt: Simplify case switch in intel_vgpu_ioctl We do not need a case switch to check cap_type_id in intel_vgpu_ioctl for various reasons (it's impossible to hit the default case in the current code, there's only one valid case to check, the error handling code overlaps in both cases, etc.). Simplify the case switch into a single if statement. This has the additional effect of simplifying the error handling code. Note that it is still currently impossible for 'if (cap_type_id == VFIO_REGION_INFO_CAP_SPARSE_MMAP)' to fail, but we should still guard against the possibility of this changing in the future. Signed-off-by: Jonathan Cavitt Cc: Andi Shyti Reviewed-by: Zhenyu Wang Reviewed-by: Andi Shyti Signed-off-by: Andi Shyti Link: https://lore.kernel.org/r/20250918214515.66926-2-jonathan.cavitt@intel.com --- diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 69830a5c49d3f..70af86d46fe8e 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -1279,20 +1279,15 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, } if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) { - switch (cap_type_id) { - case VFIO_REGION_INFO_CAP_SPARSE_MMAP: + ret = -EINVAL; + if (cap_type_id == VFIO_REGION_INFO_CAP_SPARSE_MMAP) ret = vfio_info_add_capability(&caps, &sparse->header, struct_size(sparse, areas, sparse->nr_areas)); - if (ret) { - kfree(sparse); - return ret; - } - break; - default: + if (ret) { kfree(sparse); - return -EINVAL; + return ret; } }