Re: [PATCH v5 13/23] iommu: introduce device fault report API
From: Jacob Pan
Date: Tue Sep 25 2018 - 18:15:50 EST
On Tue, 25 Sep 2018 15:58:41 +0100
Jean-Philippe Brucker <jean-philippe.brucker@xxxxxxx> wrote:
> Hi Jacob,
>
> Just two minor things below, that I noticed while using fault handlers
> for SVA. From my perspective the series is fine otherwise
>
> On 11/05/2018 21:54, Jacob Pan wrote:
> > +int iommu_unregister_device_fault_handler(struct device *dev)
> > +{
> > +ÂÂÂÂÂÂ struct iommu_param *param = dev->iommu_param;
> > +ÂÂÂÂÂÂ int ret = 0;
> > +
> > +ÂÂÂÂÂÂ if (!param)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
> > +
> > +ÂÂÂÂÂÂ mutex_lock(¶m->lock);
>
> Could we check that param->fault_param isn't NULL here, so that the
> driver can call this function unconditionally in a cleanup path?
>
sounds good.
if (!param || param->fault_param)
return -EINVAL;
> > +ÂÂÂÂÂÂ /* we cannot unregister handler if there are pending faults
> > */
> > +ÂÂÂÂÂÂ if (!list_empty(¶m->fault_param->faults)) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = -EBUSY;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto unlock;
> > +ÂÂÂÂÂÂ }
> > +
> > +ÂÂÂÂÂÂ kfree(param->fault_param);
> > +ÂÂÂÂÂÂ param->fault_param = NULL;
> > +ÂÂÂÂÂÂ put_device(dev);
> > +unlock:
> > +ÂÂÂÂÂÂ mutex_unlock(¶m->lock);
> > +
> > +ÂÂÂÂÂÂ return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(iommu_unregister_device_fault_handler);
> > +
> > +
> > +/**
> > + * iommu_report_device_fault() - Report fault event to device
> > + * @dev: the device
> > + * @evt: fault event data
> > + *
> > + * Called by IOMMU model specific drivers when fault is detected,
> > typically
> > + * in a threaded IRQ handler.
> > + *
> > + * Return 0 on success, or an error.
> > + */
> > +int iommu_report_device_fault(struct device *dev, struct
> > iommu_fault_event *evt)
> > +{
> > +ÂÂÂÂÂÂ int ret = 0;
> > +ÂÂÂÂÂÂ struct iommu_fault_event *evt_pending;
> > +ÂÂÂÂÂÂ struct iommu_fault_param *fparam;
> > +
> > +ÂÂÂÂÂÂ /* iommu_param is allocated when device is added to group */
> > +ÂÂÂÂÂÂ if (!dev->iommu_param | !evt)
>
> Should probably be ||
>
your are right, thanks!