On Mon, Feb 13, 2023 at 07:13:36AM -0800, Yi Liu wrote:
> +static struct vfio_device *vfio_device_from_file(struct file *file)
> +{
> +     struct vfio_device_file *df = file->private_data;
> +
> +     if (file->f_op != &vfio_device_fops)
> +             return NULL;
> +     return df->device;
> +}
> +
>  /**
>   * vfio_file_is_valid - True if the file is usable with VFIO APIS
>   * @file: VFIO group file or VFIO device file
>   */
>  bool vfio_file_is_valid(struct file *file)
>  {
> -     return vfio_group_from_file(file);
> +     return vfio_group_from_file(file) ||
> +            vfio_device_from_file(file);
>  }
>  EXPORT_SYMBOL_GPL(vfio_file_is_valid);

This can only succeed on a device cdev that has been fully opened.

Jason

Reply via email to