From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Sent: Wednesday, April 23, 2025 11:10 AM
num = ida_alloc_range(&iommu->domain_ida, FLPT_DEFAULT_DID +
1,
cap_ndoms(iommu->cap) - 1, GFP_KERNEL);
- if (num < 0) {
- pr_err("%s: No free domain ids\n", iommu->name);
this error message could be kept.
Hmm, I've considered this. My thought was that xa_store() failure only
- goto err_unlock;
- }
+ if (num < 0)
+ return num;
info->refcnt = 1;
info->did = num;
info->iommu = iommu;
- curr = xa_cmpxchg(&domain->iommu_array, iommu->seq_id,
- NULL, info, GFP_KERNEL);
- if (curr) {
- ret = xa_err(curr) ? : -EBUSY;
- goto err_clear;
- }
- return 0;
-
-err_clear:
- ida_free(&iommu->domain_ida, info->did);
-err_unlock:
- kfree(info);
- return ret;
+ return xa_err(xa_store(&domain->iommu_array, iommu->seq_id,
+ no_free_ptr(info), GFP_KERNEL));
}
no_free_ptr() should be used before successful return. Here xa_store()
could return error but at that point no auto free as no_free_ptr() already
changes 'info' to NULL. then memory leak.