Re: [PATCH v2 3/4] iommufd: Add IOMMU_DEVICE_GET_HW_INFO
From: Jason Gunthorpe
Date: Thu Mar 09 2023 - 12:21:16 EST
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.
Jason