On Thu, Oct 23, 2025 at 08:09:36PM -0300, Jason Gunthorpe wrote:
> No driver uses it now, all are using get_region_info_caps().
>
> Signed-off-by: Jason Gunthorpe <[email protected]>
> ---
> drivers/vfio/vfio_main.c | 50 +++++++++++++++++-----------------------
> include/linux/vfio.h | 2 --
> 2 files changed, 21 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 82e7d79b1f9fe2..f911c1980c9420 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1263,48 +1263,40 @@ static long vfio_get_region_info(struct vfio_device
> *device,
> struct vfio_region_info __user *arg)
> {
> unsigned long minsz = offsetofend(struct vfio_region_info, offset);
> + struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> struct vfio_region_info info = {};
> int ret;
>
> + if (unlikely(!device->ops->get_region_info_caps))
> + return -EINVAL;
> +
> if (copy_from_user(&info, arg, minsz))
> return -EFAULT;
> if (info.argsz < minsz)
> return -EINVAL;
>
> - if (device->ops->get_region_info_caps) {
> - struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> + ret = device->ops->get_region_info_caps(device, &info, &caps);
> + if (ret)
> + return ret;
Shall we kfree(caps.buf); before returning?
> - ret = device->ops->get_region_info_caps(device, &info, &caps);
> - if (ret)
> - return ret;
> -
> - if (caps.size) {
> - info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> - if (info.argsz < sizeof(info) + caps.size) {
> - info.argsz = sizeof(info) + caps.size;
> - info.cap_offset = 0;
> - } else {
> - vfio_info_cap_shift(&caps, sizeof(info));
> - if (copy_to_user(arg + 1, caps.buf,
> - caps.size)) {
> - kfree(caps.buf);
> - return -EFAULT;
> - }
> - info.cap_offset = sizeof(info);
> + if (caps.size) {
> + info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> + if (info.argsz < sizeof(info) + caps.size) {
> + info.argsz = sizeof(info) + caps.size;
> + info.cap_offset = 0;
> + } else {
> + vfio_info_cap_shift(&caps, sizeof(info));
> + if (copy_to_user(arg + 1, caps.buf, caps.size)) {
> + kfree(caps.buf);
> + return -EFAULT;
> }
> - kfree(caps.buf);
> + info.cap_offset = sizeof(info);
> }
> -
> - if (copy_to_user(arg, &info, minsz))
> - return -EFAULT;
> - } else if (device->ops->get_region_info) {
> - ret = device->ops->get_region_info(device, arg);
> - if (ret)
> - return ret;
> - } else {
> - return -EINVAL;
> + kfree(caps.buf);
> }
>
> + if (copy_to_user(arg, &info, minsz))
> + return -EFAULT;
> return 0;
> }
>
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index 6311ddc837701d..8e1ddb48b9b54e 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -133,8 +133,6 @@ struct vfio_device_ops {
> size_t count, loff_t *size);
> long (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
> unsigned long arg);
> - int (*get_region_info)(struct vfio_device *vdev,
> - struct vfio_region_info __user *arg);
> int (*get_region_info_caps)(struct vfio_device *vdev,
> struct vfio_region_info *info,
> struct vfio_info_cap *caps);
Thanks,
Praan