RE: [PATCH v2 3/4] iommufd: Add IOMMU_DEVICE_GET_HW_INFO

From: Liu, Yi L
Date: Fri Mar 10 2023 - 03:08:50 EST


> From: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Sent: Friday, March 10, 2023 1:21 AM
>
> On Thu, Mar 09, 2023 at 09:50:18PM +0800, Baolu Lu wrote:
>
> > > + if (cmd->flags || cmd->__reserved || !cmd->data_len)
> > > + return -EOPNOTSUPP;
> > > +
> > > + idev = iommufd_get_device(ucmd, cmd->dev_id);
> > > + if (IS_ERR(idev))
> > > + return PTR_ERR(idev);
> > > +
> > > + ops = dev_iommu_ops(idev->dev);
> > > + if (!ops || !ops->hw_info) {
> >
> > dev_iommu_ops() will never return a NULL.
> >
> > Need below check
> >
> > dev->iommu && dev->iommu->iommu_dev
> >
> > before dev_iommu_ops(). Perhaps something like below?
> >
> > if (!dev->iommu || !dev->iommu->iommu_dev)
> > return -EINVAL;
>
> At this point the device has become owned through the ownership API,
> it absolutely has to have an iommu and an ops. No need to check
> anything.

ok. so just needs to check hw_info callback.