diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/iommu/intel | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/iommu/intel')
| -rw-r--r-- | drivers/iommu/intel/cache.c | 4 | ||||
| -rw-r--r-- | drivers/iommu/intel/dmar.c | 8 | ||||
| -rw-r--r-- | drivers/iommu/intel/iommu.c | 12 | ||||
| -rw-r--r-- | drivers/iommu/intel/irq_remapping.c | 6 | ||||
| -rw-r--r-- | drivers/iommu/intel/nested.c | 2 | ||||
| -rw-r--r-- | drivers/iommu/intel/pasid.c | 2 | ||||
| -rw-r--r-- | drivers/iommu/intel/perf.c | 4 | ||||
| -rw-r--r-- | drivers/iommu/intel/perfmon.c | 2 | ||||
| -rw-r--r-- | drivers/iommu/intel/svm.c | 2 |
9 files changed, 21 insertions, 21 deletions
diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c index 385ae5cfb30d..e43c93fb9b1d 100644 --- a/drivers/iommu/intel/cache.c +++ b/drivers/iommu/intel/cache.c @@ -49,7 +49,7 @@ int cache_tag_assign(struct dmar_domain *domain, u16 did, struct device *dev, struct list_head *prev; unsigned long flags; - tag = kzalloc(sizeof(*tag), GFP_KERNEL); + tag = kzalloc_obj(*tag, GFP_KERNEL); if (!tag) return -ENOMEM; @@ -123,7 +123,7 @@ static int domain_qi_batch_alloc(struct dmar_domain *domain) if (domain->qi_batch) goto out_unlock; - domain->qi_batch = kzalloc(sizeof(*domain->qi_batch), GFP_ATOMIC); + domain->qi_batch = kzalloc_obj(*domain->qi_batch, GFP_ATOMIC); if (!domain->qi_batch) ret = -ENOMEM; out_unlock: diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index ec975c73cfe6..4a2143036b94 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -99,7 +99,7 @@ void *dmar_alloc_dev_scope(void *start, void *end, int *cnt) if (*cnt == 0) return NULL; - return kcalloc(*cnt, sizeof(struct dmar_dev_scope), GFP_KERNEL); + return kzalloc_objs(struct dmar_dev_scope, *cnt, GFP_KERNEL); } void dmar_free_dev_scope(struct dmar_dev_scope **devices, int *cnt) @@ -1046,7 +1046,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) return -EINVAL; } - iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); + iommu = kzalloc_obj(*iommu, GFP_KERNEL); if (!iommu) return -ENOMEM; @@ -1692,7 +1692,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) if (iommu->qi) return 0; - iommu->qi = kmalloc(sizeof(*qi), GFP_ATOMIC); + iommu->qi = kmalloc_obj(*qi, GFP_ATOMIC); if (!iommu->qi) return -ENOMEM; @@ -1713,7 +1713,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) qi->desc = desc; - qi->desc_status = kcalloc(QI_LENGTH, sizeof(int), GFP_ATOMIC); + qi->desc_status = kzalloc_objs(int, QI_LENGTH, GFP_ATOMIC); if (!qi->desc_status) { iommu_free_pages(qi->desc); kfree(qi); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 705828b06e32..3505ced050f0 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1030,7 +1030,7 @@ int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) if (domain->domain.type == IOMMU_DOMAIN_SVA) return 0; - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = kzalloc_obj(*info, GFP_KERNEL); if (!info) return -ENOMEM; @@ -1926,7 +1926,7 @@ int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg) add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK); } - rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL); + rmrru = kzalloc_obj(*rmrru, GFP_KERNEL); if (!rmrru) goto out; @@ -2779,7 +2779,7 @@ static struct dmar_domain *paging_domain_alloc(void) { struct dmar_domain *domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); + domain = kzalloc_obj(*domain, GFP_KERNEL); if (!domain) return ERR_PTR(-ENOMEM); @@ -3237,7 +3237,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) if (!iommu || !iommu->iommu.ops) return ERR_PTR(-ENODEV); - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = kzalloc_obj(*info, GFP_KERNEL); if (!info) return ERR_PTR(-ENOMEM); @@ -3576,7 +3576,7 @@ domain_add_dev_pasid(struct iommu_domain *domain, unsigned long flags; int ret; - dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL); + dev_pasid = kzalloc_obj(*dev_pasid, GFP_KERNEL); if (!dev_pasid) return ERR_PTR(-ENOMEM); @@ -3672,7 +3672,7 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, *type != IOMMU_HW_INFO_TYPE_INTEL_VTD) return ERR_PTR(-EOPNOTSUPP); - vtd = kzalloc(sizeof(*vtd), GFP_KERNEL); + vtd = kzalloc_obj(*vtd, GFP_KERNEL); if (!vtd) return ERR_PTR(-ENOMEM); diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c index ecb591e98565..105958b4a29e 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -533,7 +533,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) if (iommu->ir_table) return 0; - ir_table = kzalloc(sizeof(struct ir_table), GFP_KERNEL); + ir_table = kzalloc_obj(struct ir_table, GFP_KERNEL); if (!ir_table) return -ENOMEM; @@ -1426,7 +1426,7 @@ static int intel_irq_remapping_alloc(struct irq_domain *domain, return ret; ret = -ENOMEM; - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = kzalloc_obj(*data, GFP_KERNEL); if (!data) goto out_free_parent; @@ -1448,7 +1448,7 @@ static int intel_irq_remapping_alloc(struct irq_domain *domain, } if (i > 0) { - ird = kzalloc(sizeof(*ird), GFP_KERNEL); + ird = kzalloc_obj(*ird, GFP_KERNEL); if (!ird) goto out_free_data; /* Initialize the common data */ diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index e9a440e9c960..2b979bec56ce 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -218,7 +218,7 @@ intel_iommu_domain_alloc_nested(struct device *dev, struct iommu_domain *parent, if (ret) return ERR_PTR(ret); - domain = kzalloc(sizeof(*domain), GFP_KERNEL_ACCOUNT); + domain = kzalloc_obj(*domain, GFP_KERNEL_ACCOUNT); if (!domain) return ERR_PTR(-ENOMEM); diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index b63a71904cfb..5ffe84dee862 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -50,7 +50,7 @@ int intel_pasid_alloc_table(struct device *dev) if (WARN_ON(info->pasid_table)) return -EEXIST; - pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL); + pasid_table = kzalloc_obj(*pasid_table, GFP_KERNEL); if (!pasid_table) return -ENOMEM; diff --git a/drivers/iommu/intel/perf.c b/drivers/iommu/intel/perf.c index dceeadc3ee7c..02168f2f20a4 100644 --- a/drivers/iommu/intel/perf.c +++ b/drivers/iommu/intel/perf.c @@ -33,8 +33,8 @@ int dmar_latency_enable(struct intel_iommu *iommu, enum latency_type type) spin_lock_irqsave(&latency_lock, flags); if (!iommu->perf_statistic) { - iommu->perf_statistic = kcalloc(DMAR_LATENCY_NUM, sizeof(*lstat), - GFP_ATOMIC); + iommu->perf_statistic = kzalloc_objs(*lstat, DMAR_LATENCY_NUM, + GFP_ATOMIC); if (!iommu->perf_statistic) { ret = -ENOMEM; goto unlock_out; diff --git a/drivers/iommu/intel/perfmon.c b/drivers/iommu/intel/perfmon.c index 75f493bcb353..76b62f2c8d92 100644 --- a/drivers/iommu/intel/perfmon.c +++ b/drivers/iommu/intel/perfmon.c @@ -591,7 +591,7 @@ int alloc_iommu_pmu(struct intel_iommu *iommu) if (!ecmd_has_pmu_essential(iommu)) return -ENODEV; - iommu_pmu = kzalloc(sizeof(*iommu_pmu), GFP_KERNEL); + iommu_pmu = kzalloc_obj(*iommu_pmu, GFP_KERNEL); if (!iommu_pmu) return -ENOMEM; diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 71de7947971f..be165cb9d01e 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -210,7 +210,7 @@ struct iommu_domain *intel_svm_domain_alloc(struct device *dev, if (ret) return ERR_PTR(ret); - domain = kzalloc(sizeof(*domain), GFP_KERNEL); + domain = kzalloc_obj(*domain, GFP_KERNEL); if (!domain) return ERR_PTR(-ENOMEM); |
