Skip to content

Commit 7d12578

Browse files
yiliu1765jgunthorpe
authored andcommitted
vfio: Check the presence for iommufd callbacks in __vfio_register_dev()
After making the no-DMA drivers (samples/vfio-mdev) providing iommufd callbacks, __vfio_register_dev() should check the presence of the iommufd callbacks if CONFIG_IOMMUFD is enabled. Link: https://lore.kernel.org/r/20230327093351.44505-7-yi.l.liu@intel.com Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Terrence Xu <terrence.xu@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 0a782d1 commit 7d12578

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

drivers/vfio/iommufd.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx)
3232
return 0;
3333
}
3434

35-
if (WARN_ON(!vdev->ops->bind_iommufd))
36-
return -ENODEV;
37-
3835
ret = vdev->ops->bind_iommufd(vdev, ictx, &device_id);
3936
if (ret)
4037
return ret;

drivers/vfio/vfio_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ static int __vfio_register_dev(struct vfio_device *device,
255255
{
256256
int ret;
257257

258-
if (WARN_ON(device->ops->bind_iommufd &&
259-
(!device->ops->unbind_iommufd ||
258+
if (WARN_ON(IS_ENABLED(CONFIG_IOMMUFD) &&
259+
(!device->ops->bind_iommufd ||
260+
!device->ops->unbind_iommufd ||
260261
!device->ops->attach_ioas)))
261262
return -EINVAL;
262263

0 commit comments

Comments
 (0)