This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings.
Showing the changes to kernel/trace (4 of 304 files). Show all
Unified · Split
| @@ -945,7 +945,7 @@ int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter · 944 unmodified lines | ||
| 945 | 945 | if (num < 0) |
| 946 | 946 | return num; |
| 947 | 947 | |
| 948 | − addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL); | |
| 948 | + addrs = kzalloc_objs(*addrs, num); | |
| 949 | 949 | if (!addrs) |
| 950 | 950 | return -ENOMEM; |
| 951 | 951 | |
| @@ -2600,8 +2600,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu) · 2599 unmodified lines | ||
| 2600 | 2600 | cpu_buffer->remote = buffer->remote; |
| 2601 | 2601 | cpu_buffer->meta_page = (struct trace_buffer_meta *)(void *)desc->meta_va; |
| 2602 | 2602 | cpu_buffer->nr_pages = nr_pages; |
| 2603 | − cpu_buffer->subbuf_ids = kcalloc(cpu_buffer->nr_pages + 1, | |
| 2604 | − sizeof(*cpu_buffer->subbuf_ids), GFP_KERNEL); | |
| 2603 | + cpu_buffer->subbuf_ids = kzalloc_objs(*cpu_buffer->subbuf_ids, | |
| 2604 | + cpu_buffer->nr_pages + 1); | |
| 2605 | 2605 | if (!cpu_buffer->subbuf_ids) |
| 2606 | 2606 | goto fail_free_reader; |
| 2607 | 2607 | |
| @@ -930,7 +930,7 @@ static int __trace_eprobe_create(int argc, const char *argv[]) · 929 unmodified lines | ||
| 930 | 930 | } else |
| 931 | 931 | ep->filter_str = NULL; |
| 932 | 932 | |
| 933 | − ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | |
| 933 | + ctx = kzalloc_obj(*ctx); | |
| 934 | 934 | if (!ctx) |
| 935 | 935 | return -ENOMEM; |
| 936 | 936 | ctx->event = ep->event; |
| @@ -251,8 +251,8 @@ static int trace_remote_get(struct trace_remote *remote, int cpu) · 250 unmodified lines | ||
| 251 | 251 | if (cpu != RING_BUFFER_ALL_CPUS && !remote->pcpu_reader_locks) { |
| 252 | 252 | int lock_cpu; |
| 253 | 253 | |
| 254 | − remote->pcpu_reader_locks = kcalloc(nr_cpu_ids, sizeof(*remote->pcpu_reader_locks), | |
| 255 | − GFP_KERNEL); | |
| 254 | + remote->pcpu_reader_locks = kzalloc_objs(*remote->pcpu_reader_locks, | |
| 255 | + nr_cpu_ids); | |
| 256 | 256 | if (!remote->pcpu_reader_locks) { |
| 257 | 257 | trace_remote_try_unload(remote); |
| 258 | 258 | return -ENOMEM; |
| @@ -324,7 +324,7 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu) · 65 unmodified lines | ||
| 324 | 324 | return iter->rb_iter ? 0 : -ENOMEM; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | − iter->rb_iters = kcalloc(nr_cpu_ids, sizeof(*iter->rb_iters), GFP_KERNEL); | |
| 327 | + iter->rb_iters = kzalloc_objs(*iter->rb_iters, nr_cpu_ids); | |
| 328 | 328 | if (!iter->rb_iters) |
| 329 | 329 | return -ENOMEM; |
| 330 | 330 | |
| @@ -1204,7 +1204,7 @@ remote_events_dir_header_page_read(struct file *filp, char __user *ubuf, size_t · 873 unmodified lines | ||
| 1204 | 1204 | struct trace_seq *s; |
| 1205 | 1205 | int ret; |
| 1206 | 1206 | |
| 1207 | − s = kmalloc(sizeof(*s), GFP_KERNEL); | |
| 1207 | + s = kmalloc_obj(*s); | |
| 1208 | 1208 | if (!s) |
| 1209 | 1209 | return -ENOMEM; |
| 1210 | 1210 | |
| @@ -1227,7 +1227,7 @@ remote_events_dir_header_event_read(struct file *filp, char __user *ubuf, size_t · 16 unmodified lines | ||
| 1227 | 1227 | struct trace_seq *s; |
| 1228 | 1228 | int ret; |
| 1229 | 1229 | |
| 1230 | − s = kmalloc(sizeof(*s), GFP_KERNEL); | |
| 1230 | + s = kmalloc_obj(*s); | |
| 1231 | 1231 | if (!s) |
| 1232 | 1232 | return -ENOMEM; |
| 1233 | 1233 | |