Skip to content

Commit 8865aea

Browse files
ruanjinjie-engmhiramat
authored andcommitted
kernel: kprobes: Use struct_size()
Use struct_size() instead of hand-writing it, when allocating a structure with a flex array. This is less verbose. Link: https://lore.kernel.org/all/20230725195424.3469242-1-ruanjinjie@huawei.com/ Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 2ccdd1b commit 8865aea

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

kernel/kprobes.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,8 +2232,7 @@ int register_kretprobe(struct kretprobe *rp)
22322232
return -ENOMEM;
22332233

22342234
for (i = 0; i < rp->maxactive; i++) {
2235-
inst = kzalloc(sizeof(struct kretprobe_instance) +
2236-
rp->data_size, GFP_KERNEL);
2235+
inst = kzalloc(struct_size(inst, data, rp->data_size), GFP_KERNEL);
22372236
if (inst == NULL) {
22382237
rethook_free(rp->rh);
22392238
rp->rh = NULL;
@@ -2256,8 +2255,7 @@ int register_kretprobe(struct kretprobe *rp)
22562255

22572256
rp->rph->rp = rp;
22582257
for (i = 0; i < rp->maxactive; i++) {
2259-
inst = kzalloc(sizeof(struct kretprobe_instance) +
2260-
rp->data_size, GFP_KERNEL);
2258+
inst = kzalloc(struct_size(inst, data, rp->data_size), GFP_KERNEL);
22612259
if (inst == NULL) {
22622260
refcount_set(&rp->rph->ref, i);
22632261
free_rp_inst(rp);

0 commit comments

Comments
 (0)