Skip to content

Commit

Permalink
vifo_platform: Use vfio_alloc/put_device()
Browse files Browse the repository at this point in the history
Uses vfio_alloc/put_device() for vfio_platform_device allocation, and
moves the name field free into vfio_platform_release().

Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
  • Loading branch information
yiliu1765 committed Feb 9, 2022
1 parent b83a9c3 commit 92b20d7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
12 changes: 6 additions & 6 deletions drivers/vfio/platform/vfio_amba.c
Expand Up @@ -43,9 +43,11 @@ static int get_amba_irq(struct vfio_platform_device *vdev, int i)
static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
{
struct vfio_platform_device *vdev;
struct device *dev = &adev->dev;
int ret;

vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
vdev = vfio_alloc_device(vfio_platform_device, vdev,
dev, &vfio_platform_ops);
if (!vdev)
return -ENOMEM;

Expand All @@ -61,10 +63,9 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
vdev->get_irq = get_amba_irq;
vdev->reset_required = false;

ret = vfio_platform_probe_common(vdev, &adev->dev);
ret = vfio_platform_probe_common(vdev, dev);
if (ret) {
kfree(vdev->name);
kfree(vdev);
vfio_put_device(&vdev->vdev);
return ret;
}

Expand All @@ -77,8 +78,7 @@ static void vfio_amba_remove(struct amba_device *adev)
struct vfio_platform_device *vdev = dev_get_drvdata(&adev->dev);

vfio_platform_remove_common(vdev);
kfree(vdev->name);
kfree(vdev);
vfio_put_device(&vdev->vdev);
}

static const struct amba_id pl330_ids[] = {
Expand Down
12 changes: 8 additions & 4 deletions drivers/vfio/platform/vfio_platform.c
Expand Up @@ -39,9 +39,11 @@ static int get_platform_irq(struct vfio_platform_device *vdev, int i)
static int vfio_platform_probe(struct platform_device *pdev)
{
struct vfio_platform_device *vdev;
struct device *dev = &pdev->dev;
int ret;

vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
vdev = vfio_alloc_device(vfio_platform_device, vdev,
dev, &vfio_platform_ops);
if (!vdev)
return -ENOMEM;

Expand All @@ -52,9 +54,10 @@ static int vfio_platform_probe(struct platform_device *pdev)
vdev->get_irq = get_platform_irq;
vdev->reset_required = reset_required;

ret = vfio_platform_probe_common(vdev, &pdev->dev);
ret = vfio_platform_probe_common(vdev, dev);
if (ret) {
kfree(vdev);
vdev->name = NULL;
vfio_put_device(&vdev->vdev);
return ret;
}
dev_set_drvdata(&pdev->dev, vdev);
Expand All @@ -66,7 +69,8 @@ static int vfio_platform_remove(struct platform_device *pdev)
struct vfio_platform_device *vdev = dev_get_drvdata(&pdev->dev);

vfio_platform_remove_common(vdev);
kfree(vdev);
vdev->name = NULL;
vfio_put_device(&vdev->vdev);
return 0;
}

Expand Down
13 changes: 10 additions & 3 deletions drivers/vfio/platform/vfio_platform_common.c
Expand Up @@ -599,8 +599,17 @@ static int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_stru
return -EINVAL;
}

static const struct vfio_device_ops vfio_platform_ops = {
static void vfio_platform_release(struct vfio_device *vdev)
{
struct vfio_platform_device *vpdev =
container_of(vdev, struct vfio_platform_device, vdev);

kfree(vpdev->name);
}

const struct vfio_device_ops vfio_platform_ops = {
.name = "vfio-platform",
.release = vfio_platform_release,
.open_device = vfio_platform_open_device,
.close_device = vfio_platform_close_device,
.ioctl = vfio_platform_ioctl,
Expand Down Expand Up @@ -644,8 +653,6 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
{
int ret;

vfio_init_group_dev(&vdev->vdev, dev, &vfio_platform_ops);

ret = vfio_platform_acpi_probe(vdev, dev);
if (ret)
ret = vfio_platform_of_probe(vdev, dev);
Expand Down
2 changes: 2 additions & 0 deletions drivers/vfio/platform/vfio_platform_private.h
Expand Up @@ -78,6 +78,8 @@ struct vfio_platform_reset_node {
vfio_platform_reset_fn_t of_reset;
};

extern const struct vfio_device_ops vfio_platform_ops;

extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
struct device *dev);
void vfio_platform_remove_common(struct vfio_platform_device *vdev);
Expand Down

0 comments on commit 92b20d7

Please sign in to comment.