Skip to content

Commit 8865aea

Browse files
Ruan Jinjiemhiramat
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/[email protected]/ Signed-off-by: Ruan Jinjie <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 2ccdd1b commit 8865aea

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

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)