Re: [PATCH v2 06/12] iommu: Make dev->fault_param static

From: Jason Gunthorpe
Date: Thu Aug 10 2023 - 14:20:13 EST


On Thu, Jul 27, 2023 at 01:48:31PM +0800, Lu Baolu wrote:
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 4ba3bb692993..3e4ff984aa85 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -302,7 +302,15 @@ static int dev_iommu_get(struct device *dev)
> return -ENOMEM;
>
> mutex_init(&param->lock);
> + param->fault_param = kzalloc(sizeof(*param->fault_param), GFP_KERNEL);
> + if (!param->fault_param) {
> + kfree(param);
> + return -ENOMEM;
> + }
> + mutex_init(&param->fault_param->lock);
> + INIT_LIST_HEAD(&param->fault_param->faults);
> dev->iommu = param;

This allocation seems pointless?

If we always allocate the fault param then just don't make it a
pointer in the first place.

The appeal of allocation would be to save a few bytes in the common
case that the driver doesn't support faulting.

Which means the driver needs to make some call to enable faulting for
a device. In this case I'd continue to lazy free on release like this
patch does.

Jason