struct dma_sg_map_param {
struct sg_table sgt;
struct device *dev;
- void **buf;
u32 npages;
u32 dma_dir;
+ void *buf[] __counted_by(npages);
};
static void *dma_sg_map_benchmark_prepare(struct map_benchmark_data *map)
{
+ struct dma_sg_map_param *params;
struct scatterlist *sg;
+ u32 npages;
int i;
- struct dma_sg_map_param *params = kzalloc(sizeof(*params), GFP_KERNEL);
-
- if (!params)
- return NULL;
/*
* Set the number of scatterlist entries based on the granule.
* In SG mode, 'granule' represents the number of scatterlist entries.
* Each scatterlist entry corresponds to a single page.
*/
- params->npages = map->bparam.granule;
+ npages = map->bparam.granule;
+
+ params = kzalloc_flex(*params, buf, npages);
+ if (!params)
+ return NULL;
+
+ params->npages = npages;
params->dma_dir = map->bparam.dma_dir;
params->dev = map->dev;
- params->buf = kmalloc_array(params->npages, sizeof(*params->buf),
- GFP_KERNEL);
- if (!params->buf)
- goto out;
if (sg_alloc_table(¶ms->sgt, params->npages, GFP_KERNEL))
- goto free_buf;
+ goto free_params;
for_each_sgtable_sg(¶ms->sgt, sg, i) {
params->buf[i] = (void *)__get_free_page(GFP_KERNEL);
free_page((unsigned long)params->buf[i]);
sg_free_table(¶ms->sgt);
-free_buf:
- kfree(params->buf);
-out:
+free_params:
kfree(params);
return NULL;
}
sg_free_table(¶ms->sgt);
- kfree(params->buf);
kfree(params);
}