mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
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>
This commit is contained in:
@@ -1122,7 +1122,7 @@ int amdgpu_ttm_mmio_remap_alloc_sgt(struct amdgpu_device *adev,
|
||||
phys = adev->rmmio_remap.bus_addr + cur.start;
|
||||
|
||||
/* Build a single-entry sg_table mapped as I/O (no struct page backing). */
|
||||
*sgt = kzalloc(sizeof(**sgt), GFP_KERNEL);
|
||||
*sgt = kzalloc_obj(**sgt, GFP_KERNEL);
|
||||
if (!*sgt)
|
||||
return -ENOMEM;
|
||||
r = sg_alloc_table(*sgt, 1, GFP_KERNEL);
|
||||
@@ -1172,7 +1172,7 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo,
|
||||
struct amdgpu_ttm_tt *gtt;
|
||||
enum ttm_caching caching;
|
||||
|
||||
gtt = kzalloc(sizeof(struct amdgpu_ttm_tt), GFP_KERNEL);
|
||||
gtt = kzalloc_obj(struct amdgpu_ttm_tt, GFP_KERNEL);
|
||||
if (!gtt)
|
||||
return NULL;
|
||||
|
||||
@@ -1213,7 +1213,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
|
||||
|
||||
/* user pages are bound by amdgpu_ttm_tt_pin_userptr() */
|
||||
if (gtt->userptr) {
|
||||
ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
|
||||
ttm->sg = kzalloc_obj(struct sg_table, GFP_KERNEL);
|
||||
if (!ttm->sg)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
@@ -1880,9 +1880,9 @@ static int amdgpu_ttm_pools_init(struct amdgpu_device *adev)
|
||||
if (!adev->gmc.is_app_apu || !adev->gmc.num_mem_partitions)
|
||||
return 0;
|
||||
|
||||
adev->mman.ttm_pools = kcalloc(adev->gmc.num_mem_partitions,
|
||||
sizeof(*adev->mman.ttm_pools),
|
||||
GFP_KERNEL);
|
||||
adev->mman.ttm_pools = kzalloc_objs(*adev->mman.ttm_pools,
|
||||
adev->gmc.num_mem_partitions,
|
||||
GFP_KERNEL);
|
||||
if (!adev->mman.ttm_pools)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user