History

treewide: refresh kmalloc_obj() conversions

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.

Kees Cook committed 2 months ago

Commit 3a2c4d51 parent 90feea3304 files · +637 −726Browse files

Showing the changes to kernel/trace (4 of 304 files). Show all

Unified · Split

4 files
  1. kernel/trace/fprobe.c +1 −1
  2. kernel/trace/ring_buffer.c +2 −2
  3. kernel/trace/trace_eprobe.c +1 −1
  4. kernel/trace/trace_remote.c +5 −5
kernel/trace/fprobe.c+1−1
@@ -945,7 +945,7 @@ int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter · 944 unmodified lines
945945 if (num < 0)
946946 return num;
947947
948− addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL);
948+ addrs = kzalloc_objs(*addrs, num);
949949 if (!addrs)
950950 return -ENOMEM;
951951
kernel/trace/ring_buffer.c+2−2
@@ -2600,8 +2600,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu) · 2599 unmodified lines
26002600 cpu_buffer->remote = buffer->remote;
26012601 cpu_buffer->meta_page = (struct trace_buffer_meta *)(void *)desc->meta_va;
26022602 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);
26052605 if (!cpu_buffer->subbuf_ids)
26062606 goto fail_free_reader;
26072607
kernel/trace/trace_eprobe.c+1−1
@@ -930,7 +930,7 @@ static int __trace_eprobe_create(int argc, const char *argv[]) · 929 unmodified lines
930930 } else
931931 ep->filter_str = NULL;
932932
933− ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
933+ ctx = kzalloc_obj(*ctx);
934934 if (!ctx)
935935 return -ENOMEM;
936936 ctx->event = ep->event;
kernel/trace/trace_remote.c+5−5
@@ -251,8 +251,8 @@ static int trace_remote_get(struct trace_remote *remote, int cpu) · 250 unmodified lines
251251 if (cpu != RING_BUFFER_ALL_CPUS && !remote->pcpu_reader_locks) {
252252 int lock_cpu;
253253
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);
256256 if (!remote->pcpu_reader_locks) {
257257 trace_remote_try_unload(remote);
258258 return -ENOMEM;
@@ -324,7 +324,7 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu) · 65 unmodified lines
324324 return iter->rb_iter ? 0 : -ENOMEM;
325325 }
326326
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);
328328 if (!iter->rb_iters)
329329 return -ENOMEM;
330330
@@ -1204,7 +1204,7 @@ remote_events_dir_header_page_read(struct file *filp, char __user *ubuf, size_t · 873 unmodified lines
12041204 struct trace_seq *s;
12051205 int ret;
12061206
1207− s = kmalloc(sizeof(*s), GFP_KERNEL);
1207+ s = kmalloc_obj(*s);
12081208 if (!s)
12091209 return -ENOMEM;
12101210
@@ -1227,7 +1227,7 @@ remote_events_dir_header_event_read(struct file *filp, char __user *ubuf, size_t · 16 unmodified lines
12271227 struct trace_seq *s;
12281228 int ret;
12291229
1230− s = kmalloc(sizeof(*s), GFP_KERNEL);
1230+ s = kmalloc_obj(*s);
12311231 if (!s)
12321232 return -ENOMEM;
12331233