mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -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:
@@ -376,7 +376,7 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
|
||||
buf = tomoyo_init_log(r, len, fmt, args);
|
||||
if (!buf)
|
||||
goto out;
|
||||
entry = kzalloc(sizeof(*entry), GFP_NOFS);
|
||||
entry = kzalloc_obj(*entry, GFP_NOFS);
|
||||
if (!entry) {
|
||||
kfree(buf);
|
||||
goto out;
|
||||
|
||||
@@ -493,7 +493,7 @@ static struct tomoyo_profile *tomoyo_assign_profile
|
||||
ptr = ns->profile_ptr[profile];
|
||||
if (ptr)
|
||||
return ptr;
|
||||
entry = kzalloc(sizeof(*entry), GFP_NOFS | __GFP_NOWARN);
|
||||
entry = kzalloc_obj(*entry, GFP_NOFS | __GFP_NOWARN);
|
||||
if (mutex_lock_interruptible(&tomoyo_policy_lock))
|
||||
goto out;
|
||||
ptr = ns->profile_ptr[profile];
|
||||
@@ -2553,7 +2553,7 @@ static int tomoyo_write_stat(struct tomoyo_io_buffer *head)
|
||||
*/
|
||||
int tomoyo_open_control(const u8 type, struct file *file)
|
||||
{
|
||||
struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
|
||||
struct tomoyo_io_buffer *head = kzalloc_obj(*head, GFP_NOFS);
|
||||
|
||||
if (!head)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -708,7 +708,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
|
||||
bool reject_on_transition_failure = false;
|
||||
const struct tomoyo_path_info *candidate;
|
||||
struct tomoyo_path_info exename;
|
||||
struct tomoyo_execve *ee = kzalloc(sizeof(*ee), GFP_NOFS);
|
||||
struct tomoyo_execve *ee = kzalloc_obj(*ee, GFP_NOFS);
|
||||
|
||||
if (!ee)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user