static int vfio_mdev_probe(struct device *dev)
{
struct mdev_device *mdev = to_mdev_device(dev);
+ struct vfio_device *vdev;
+ int ret;
- return vfio_add_group_dev(dev, &vfio_mdev_dev_ops, mdev);
+ vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
+ if (!vdev)
+ return -ENOMEM;
+
+ vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops, mdev);
+ ret = vfio_register_group_dev(vdev);
+ if (ret) {
+ kfree(vdev);
+ return ret;
+ }
+ dev_set_drvdata(&mdev->dev, vdev);
+ return 0;
}
static void vfio_mdev_remove(struct device *dev)
{
- vfio_del_group_dev(dev);
+ struct vfio_device *vdev = dev_get_drvdata(dev);
+
+ vfio_unregister_group_dev(vdev);
+ kfree(vdev);
}
static struct mdev_driver vfio_mdev_driver = {
/*
* vfio_iommu_group_{get,put} are only intended for VFIO bus driver probe
* and remove functions, any use cases other than acquiring the first
- * reference for the purpose of calling vfio_add_group_dev() or removing
- * that symmetric reference after vfio_del_group_dev() should use the raw
+ * reference for the purpose of calling vfio_register_group_dev() or removing
+ * that symmetric reference after vfio_unregister_group_dev() should use the raw
* iommu_group_{get,put} functions. In particular, vfio_iommu_group_put()
* removes the device from the dummy group and cannot be nested.
*/
}
EXPORT_SYMBOL_GPL(vfio_register_group_dev);
-int vfio_add_group_dev(struct device *dev, const struct vfio_device_ops *ops,
- void *device_data)
-{
- struct vfio_device *device;
- int ret;
-
- device = kzalloc(sizeof(*device), GFP_KERNEL);
- if (!device)
- return -ENOMEM;
-
- vfio_init_group_dev(device, dev, ops, device_data);
- ret = vfio_register_group_dev(device);
- if (ret)
- goto err_kfree;
- dev_set_drvdata(dev, device);
- return 0;
-
-err_kfree:
- kfree(device);
- return ret;
-}
-EXPORT_SYMBOL_GPL(vfio_add_group_dev);
-
/**
* Get a reference to the vfio_device for a device. Even if the
* caller thinks they own the device, they could be racing with a
}
EXPORT_SYMBOL_GPL(vfio_unregister_group_dev);
-void *vfio_del_group_dev(struct device *dev)
-{
- struct vfio_device *device = dev_get_drvdata(dev);
- void *device_data = device->device_data;
-
- vfio_unregister_group_dev(device);
- dev_set_drvdata(dev, NULL);
- kfree(device);
- return device_data;
-}
-EXPORT_SYMBOL_GPL(vfio_del_group_dev);
-
/**
* VFIO base fd, /dev/vfio/vfio
*/
void vfio_init_group_dev(struct vfio_device *device, struct device *dev,
const struct vfio_device_ops *ops, void *device_data);
int vfio_register_group_dev(struct vfio_device *device);
-extern int vfio_add_group_dev(struct device *dev,
- const struct vfio_device_ops *ops,
- void *device_data);
-
-extern void *vfio_del_group_dev(struct device *dev);
void vfio_unregister_group_dev(struct vfio_device *device);
extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
extern void vfio_device_put(struct vfio_device *device);