Skip to content

Commit 845cbf3

Browse files
committed
tracing/probes: Use struct_size() instead of defining custom macros
Remove SIZEOF_TRACE_KPROBE() and SIZEOF_TRACE_UPROBE() and use struct_size() as that's what it is made for. No need to have custom macros. Especially since struct_size() has some extra memory checks for correctness. Link: https://lkml.kernel.org/r/[email protected] Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent bc1b973 commit 845cbf3

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ static struct trace_kprobe *to_trace_kprobe(struct dyn_event *ev)
8080
for_each_dyn_event(dpos) \
8181
if (is_trace_kprobe(dpos) && (pos = to_trace_kprobe(dpos)))
8282

83-
#define SIZEOF_TRACE_KPROBE(n) \
84-
(offsetof(struct trace_kprobe, tp.args) + \
85-
(sizeof(struct probe_arg) * (n)))
86-
8783
static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
8884
{
8985
return tk->rp.handler != NULL;
@@ -265,7 +261,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
265261
struct trace_kprobe *tk;
266262
int ret = -ENOMEM;
267263

268-
tk = kzalloc(SIZEOF_TRACE_KPROBE(nargs), GFP_KERNEL);
264+
tk = kzalloc(struct_size(tk, tp.args, nargs), GFP_KERNEL);
269265
if (!tk)
270266
return ERR_PTR(ret);
271267

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ static struct trace_uprobe *to_trace_uprobe(struct dyn_event *ev)
8383
for_each_dyn_event(dpos) \
8484
if (is_trace_uprobe(dpos) && (pos = to_trace_uprobe(dpos)))
8585

86-
#define SIZEOF_TRACE_UPROBE(n) \
87-
(offsetof(struct trace_uprobe, tp.args) + \
88-
(sizeof(struct probe_arg) * (n)))
89-
9086
static int register_uprobe_event(struct trace_uprobe *tu);
9187
static int unregister_uprobe_event(struct trace_uprobe *tu);
9288

@@ -340,7 +336,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
340336
struct trace_uprobe *tu;
341337
int ret;
342338

343-
tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL);
339+
tu = kzalloc(struct_size(tu, tp.args, nargs), GFP_KERNEL);
344340
if (!tu)
345341
return ERR_PTR(-ENOMEM);
346342

0 commit comments

Comments
 (0)