@@ -1154,13 +1154,23 @@ const struct file_operations vfio_device_fops = {
.mmap = vfio_device_fops_mmap,
};
+static struct vfio_device *vfio_device_from_file(struct file *file)
+{
+ struct vfio_device *device = file->private_data;
+
+ if (file->f_op != &vfio_device_fops)
+ return NULL;
+ return device;
+}
+
/**
* vfio_file_is_valid - True if the file is valid vfio file
* @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);
@@ -1174,12 +1184,17 @@ EXPORT_SYMBOL_GPL(vfio_file_is_valid);
bool vfio_file_has_dev(struct file *file, struct vfio_device *device)
{
struct vfio_group *group;
+ struct vfio_device *vdev;
group = vfio_group_from_file(file);
- if (!group)
- return false;
+ if (group)
+ return vfio_group_has_dev(group, device);
+
+ vdev = vfio_device_from_file(file);
+ if (vdev)
+ return vdev == device;
- return vfio_group_has_dev(group, device);
+ return false;
}
EXPORT_SYMBOL_GPL(vfio_file_has_dev);