On Wed, Mar 10, 2021 at 08:36:34AM +0100, Christoph Hellwig wrote: > On Tue, Mar 09, 2021 at 05:38:51PM -0400, Jason Gunthorpe wrote: > > This tidies a few confused places that think they can have a refcount on > > the vfio_device but the device_data could be NULL, that isn't possible by > > design. > > > > Most of the change falls out when struct vfio_devices is updated to just > > store the struct vfio_pci_device itself. This wasn't possible before > > because there was no easy way to get from the 'struct vfio_pci_device' to > > the 'struct vfio_device' to put back the refcount. > > > > Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> > > drivers/vfio/pci/vfio_pci.c | 45 ++++++++++++------------------------- > > 1 file changed, 14 insertions(+), 31 deletions(-) > > > > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > > index af5696a96a76e0..4b0d60f7602e40 100644 > > +++ b/drivers/vfio/pci/vfio_pci.c > > @@ -534,7 +534,7 @@ static struct vfio_pci_device *get_pf_vdev(struct vfio_pci_device *vdev, > > return NULL; > > } > > > > - return vfio_device_data(*pf_dev); > > + return container_of(*pf_dev, struct vfio_pci_device, vdev); > > I think it would be useful to just return the vfio_device and let > the caller do the container_of() here, maybe as a followup. The callers seem to need the vfio_pci_device *? In a later series this function gets transformed into this: device_lock(&physfn->dev); vdev = vfio_pci_get_drvdata(physfn); if (!vdev) { device_unlock(&physfn->dev); return NULL; } vfio_device_get(&vdev->vdev); device_unlock(&physfn->dev); There is no container_of here because the drvdata now points at the struct vfio_pci_device Jason