On Fri, 12 Mar 2021 20:55:56 -0400 Jason Gunthorpe <jgg@xxxxxxxxxx> wrote: > platform already allocates a struct vfio_platform_device with exactly > the same lifetime as vfio_device, switch to the new API and embed > vfio_device in vfio_platform_device. > > Reviewed-by: Christoph Hellwig <hch@xxxxxx> > Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> > --- > drivers/vfio/platform/vfio_amba.c | 8 ++++--- > drivers/vfio/platform/vfio_platform.c | 21 ++++++++--------- > drivers/vfio/platform/vfio_platform_common.c | 23 +++++++------------ > drivers/vfio/platform/vfio_platform_private.h | 5 ++-- > 4 files changed, 26 insertions(+), 31 deletions(-) > > diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c > index 3626c21501017e..f970eb2a999f29 100644 > --- a/drivers/vfio/platform/vfio_amba.c > +++ b/drivers/vfio/platform/vfio_amba.c > @@ -66,16 +66,18 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) > if (ret) { > kfree(vdev->name); > kfree(vdev); > + return ret; > } > > - return ret; > + dev_set_drvdata(&adev->dev, vdev); > + return 0; > } > > static void vfio_amba_remove(struct amba_device *adev) > { > - struct vfio_platform_device *vdev = > - vfio_platform_remove_common(&adev->dev); > + struct vfio_platform_device *vdev = dev_get_drvdata(&adev->dev); > > + vfio_platform_remove_common(vdev); > kfree(vdev->name); > kfree(vdev); > } > diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c > index 9fb6818cea12cb..f7b3f64ecc7f6c 100644 > --- a/drivers/vfio/platform/vfio_platform.c > +++ b/drivers/vfio/platform/vfio_platform.c > @@ -54,23 +54,22 @@ static int vfio_platform_probe(struct platform_device *pdev) > vdev->reset_required = reset_required; > > ret = vfio_platform_probe_common(vdev, &pdev->dev); > - if (ret) > + if (ret) { > kfree(vdev); > - > - return ret; > + return ret; > + } > + dev_set_drvdata(&pdev->dev, vdev); > + return 0; > } > > static int vfio_platform_remove(struct platform_device *pdev) > { > - struct vfio_platform_device *vdev; > - > - vdev = vfio_platform_remove_common(&pdev->dev); > - if (vdev) { > - kfree(vdev); > - return 0; > - } > + struct vfio_platform_device *vdev = dev_get_drvdata(&pdev->dev); > > - return -EINVAL; > + vfio_platform_remove_common(vdev); > + kfree(vdev->name); We don't own that to free it, _probe set this via: vdev->name = pdev->name; Thanks, Alex