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
945 if (num < 0)945 if (num < 0)
946 return num;946 return num;
947 947
948 addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL);948 addrs = kzalloc_objs(*addrs, num);
949 if (!addrs)949 if (!addrs)
950 return -ENOMEM;950 return -ENOMEM;
951 951
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
2600 cpu_buffer->remote = buffer->remote;2600 cpu_buffer->remote = buffer->remote;
2601 cpu_buffer->meta_page = (struct trace_buffer_meta *)(void *)desc->meta_va;2601 cpu_buffer->meta_page = (struct trace_buffer_meta *)(void *)desc->meta_va;
2602 cpu_buffer->nr_pages = nr_pages;2602 cpu_buffer->nr_pages = nr_pages;
2603 cpu_buffer->subbuf_ids = kcalloc(cpu_buffer->nr_pages + 1,2603 cpu_buffer->subbuf_ids = kzalloc_objs(*cpu_buffer->subbuf_ids,
2604 sizeof(*cpu_buffer->subbuf_ids), GFP_KERNEL);2604 cpu_buffer->nr_pages + 1);
2605 if (!cpu_buffer->subbuf_ids)2605 if (!cpu_buffer->subbuf_ids)
2606 goto fail_free_reader;2606 goto fail_free_reader;
2607 2607
kernel/trace/trace_eprobe.c+1−1
@@ -930,7 +930,7 @@ static int __trace_eprobe_create(int argc, const char *argv[]) · 929 unmodified lines
930 } else930 } else
931 ep->filter_str = NULL;931 ep->filter_str = NULL;
932 932
933 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);933 ctx = kzalloc_obj(*ctx);
934 if (!ctx)934 if (!ctx)
935 return -ENOMEM;935 return -ENOMEM;
936 ctx->event = ep->event;936 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
251 if (cpu != RING_BUFFER_ALL_CPUS && !remote->pcpu_reader_locks) {251 if (cpu != RING_BUFFER_ALL_CPUS && !remote->pcpu_reader_locks) {
252 int lock_cpu;252 int lock_cpu;
253 253
254 remote->pcpu_reader_locks = kcalloc(nr_cpu_ids, sizeof(*remote->pcpu_reader_locks),254 remote->pcpu_reader_locks = kzalloc_objs(*remote->pcpu_reader_locks,
255 GFP_KERNEL);255 nr_cpu_ids);
256 if (!remote->pcpu_reader_locks) {256 if (!remote->pcpu_reader_locks) {
257 trace_remote_try_unload(remote);257 trace_remote_try_unload(remote);
258 return -ENOMEM;258 return -ENOMEM;
@@ -324,7 +324,7 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu) · 65 unmodified lines
324 return iter->rb_iter ? 0 : -ENOMEM;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 if (!iter->rb_iters)328 if (!iter->rb_iters)
329 return -ENOMEM;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 struct trace_seq *s;1204 struct trace_seq *s;
1205 int ret;1205 int ret;
1206 1206
1207 s = kmalloc(sizeof(*s), GFP_KERNEL);1207 s = kmalloc_obj(*s);
1208 if (!s)1208 if (!s)
1209 return -ENOMEM;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 struct trace_seq *s;1227 struct trace_seq *s;
1228 int ret;1228 int ret;
1229 1229
1230 s = kmalloc(sizeof(*s), GFP_KERNEL);1230 s = kmalloc_obj(*s);
1231 if (!s)1231 if (!s)
1232 return -ENOMEM;1232 return -ENOMEM;
1233 1233