mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08: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:
@@ -905,7 +905,7 @@ __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa
|
||||
size_t config_length;
|
||||
struct xe_bb *bb;
|
||||
|
||||
oa_bo = kzalloc(sizeof(*oa_bo), GFP_KERNEL);
|
||||
oa_bo = kzalloc_obj(*oa_bo, GFP_KERNEL);
|
||||
if (!oa_bo)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
@@ -997,7 +997,7 @@ static int xe_oa_emit_oa_config(struct xe_oa_stream *stream, struct xe_oa_config
|
||||
int i, err, num_signal = 0;
|
||||
struct dma_fence *fence;
|
||||
|
||||
ofence = kzalloc(sizeof(*ofence), GFP_KERNEL);
|
||||
ofence = kzalloc_obj(*ofence, GFP_KERNEL);
|
||||
if (!ofence) {
|
||||
err = -ENOMEM;
|
||||
goto exit;
|
||||
@@ -1408,7 +1408,8 @@ static int xe_oa_parse_syncs(struct xe_oa *oa,
|
||||
}
|
||||
|
||||
if (param->num_syncs) {
|
||||
param->syncs = kcalloc(param->num_syncs, sizeof(*param->syncs), GFP_KERNEL);
|
||||
param->syncs = kzalloc_objs(*param->syncs, param->num_syncs,
|
||||
GFP_KERNEL);
|
||||
if (!param->syncs) {
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
@@ -1852,7 +1853,7 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
|
||||
if (ret)
|
||||
goto exit;
|
||||
|
||||
stream = kzalloc(sizeof(*stream), GFP_KERNEL);
|
||||
stream = kzalloc_obj(*stream, GFP_KERNEL);
|
||||
if (!stream) {
|
||||
ret = -ENOMEM;
|
||||
goto err_syncobj;
|
||||
@@ -2259,7 +2260,7 @@ xe_oa_alloc_regs(struct xe_oa *oa, bool (*is_valid)(struct xe_oa *oa, u32 addr),
|
||||
int err;
|
||||
u32 i;
|
||||
|
||||
oa_regs = kmalloc_array(n_regs, sizeof(*oa_regs), GFP_KERNEL);
|
||||
oa_regs = kmalloc_objs(*oa_regs, n_regs, GFP_KERNEL);
|
||||
if (!oa_regs)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
@@ -2361,7 +2362,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
|
||||
XE_IOCTL_DBG(oa->xe, !arg->n_regs))
|
||||
return -EINVAL;
|
||||
|
||||
oa_config = kzalloc(sizeof(*oa_config), GFP_KERNEL);
|
||||
oa_config = kzalloc_obj(*oa_config, GFP_KERNEL);
|
||||
if (!oa_config)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user