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 /fs/proc | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-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 'fs/proc')
| -rw-r--r-- | fs/proc/kcore.c | 6 | ||||
| -rw-r--r-- | fs/proc/root.c | 4 | ||||
| -rw-r--r-- | fs/proc/task_mmu.c | 5 |
3 files changed, 7 insertions, 8 deletions
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 728630b10fdf..55438bc0afc8 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -143,7 +143,7 @@ static int kcore_ram_list(struct list_head *head) { struct kcore_list *ent; - ent = kmalloc(sizeof(*ent), GFP_KERNEL); + ent = kmalloc_obj(*ent, GFP_KERNEL); if (!ent) return -ENOMEM; ent->addr = (unsigned long)__va(0); @@ -178,7 +178,7 @@ get_sparsemem_vmemmap_info(struct kcore_list *ent, struct list_head *head) end = tmp->addr; } if (start < end) { - vmm = kmalloc(sizeof(*vmm), GFP_KERNEL); + vmm = kmalloc_obj(*vmm, GFP_KERNEL); if (!vmm) return 0; vmm->addr = start; @@ -210,7 +210,7 @@ kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg) p = pfn_to_page(pfn); - ent = kmalloc(sizeof(*ent), GFP_KERNEL); + ent = kmalloc_obj(*ent, GFP_KERNEL); if (!ent) return -ENOMEM; ent->addr = (unsigned long)page_to_virt(p); diff --git a/fs/proc/root.c b/fs/proc/root.c index d8ca41d823e4..fb0ccacb08e6 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -249,7 +249,7 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) struct proc_fs_info *fs_info; int ret; - fs_info = kzalloc(sizeof(*fs_info), GFP_KERNEL); + fs_info = kzalloc_obj(*fs_info, GFP_KERNEL); if (!fs_info) return -ENOMEM; @@ -331,7 +331,7 @@ static int proc_init_fs_context(struct fs_context *fc) { struct proc_fs_context *ctx; - ctx = kzalloc(sizeof(struct proc_fs_context), GFP_KERNEL); + ctx = kzalloc_obj(struct proc_fs_context, GFP_KERNEL); if (!ctx) return -ENOMEM; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index d7d52e259055..0418511f69fe 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1534,7 +1534,7 @@ static int smaps_rollup_open(struct inode *inode, struct file *file) int ret; struct proc_maps_private *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL_ACCOUNT); + priv = kzalloc_obj(*priv, GFP_KERNEL_ACCOUNT); if (!priv) return -ENOMEM; @@ -2981,8 +2981,7 @@ static int pagemap_scan_init_bounce_buffer(struct pagemap_scan_private *p) p->vec_buf_len = min_t(size_t, PAGEMAP_WALK_SIZE >> PAGE_SHIFT, p->arg.vec_len); - p->vec_buf = kmalloc_array(p->vec_buf_len, sizeof(*p->vec_buf), - GFP_KERNEL); + p->vec_buf = kmalloc_objs(*p->vec_buf, p->vec_buf_len, GFP_KERNEL); if (!p->vec_buf) return -ENOMEM; |
