RE: [PATCH v5 11/12] iommu: Consolidate per-device fault data management

From: Tian, Kevin
Date: Mon Sep 25 2023 - 02:55:34 EST


> From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Sent: Thursday, September 14, 2023 4:57 PM
>
> +
> +/* Caller must hold a reference of the fault parameter. */
> +static void iopf_put_dev_fault_param(struct iommu_fault_param
> *fault_param)
> +{
> + struct device *dev = fault_param->dev;
> + struct dev_iommu *param = dev->iommu;
> +
> + mutex_lock(&param->lock);
> + if (WARN_ON(fault_param->users <= 0 ||
> + fault_param != param->fault_param)) {
> + mutex_unlock(&param->lock);
> + return;
> + }
> +
> + if (--fault_param->users == 0) {
> + param->fault_param = NULL;
> + kfree(fault_param);
> + put_device(dev);
> + }

this could be a helper to be shared with iopf_queue_remove_device().

Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>