aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vfio
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2021-03-30 09:53:07 -0600
committerAlex Williamson <alex.williamson@redhat.com>2021-04-06 11:55:11 -0600
commit1ae1b20f6f2c67659c963e5fe58f9b4a47df9f12 (patch)
tree991269a68f26a64aa1e3ea14941f2825704d2176 /drivers/vfio
parentvfio/pci: Use vfio_init/register/unregister_group_dev (diff)
downloadlinux-dev-1ae1b20f6f2c67659c963e5fe58f9b4a47df9f12.tar.xz
linux-dev-1ae1b20f6f2c67659c963e5fe58f9b4a47df9f12.zip
vfio/mdev: Use vfio_init/register/unregister_group_dev
mdev gets little benefit because it doesn't actually do anything, however it is the last user, so move the vfio_init/register/unregister_group_dev() code here for now. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Liu Yi L <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Message-Id: <10-v3-225de1400dfc+4e074-vfio1_jgg@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio')
-rw-r--r--drivers/vfio/mdev/vfio_mdev.c20
-rw-r--r--drivers/vfio/vfio.c39
2 files changed, 20 insertions, 39 deletions
diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
index b52eea128549..4043cc91f952 100644
--- a/drivers/vfio/mdev/vfio_mdev.c
+++ b/drivers/vfio/mdev/vfio_mdev.c
@@ -124,13 +124,29 @@ static const struct vfio_device_ops vfio_mdev_dev_ops = {
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 = {
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 2ea430de505b..180b4ab02d11 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -99,8 +99,8 @@ MODULE_PARM_DESC(enable_unsafe_noiommu_mode, "Enable UNSAFE, no-IOMMU mode. Thi
/*
* 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.
*/
@@ -799,29 +799,6 @@ int vfio_register_group_dev(struct vfio_device *device)
}
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
@@ -962,18 +939,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
}
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
*/