Commit 8865aea0 authored by Ruan Jinjie's avatar Ruan Jinjie Committed by Masami Hiramatsu (Google)
Browse files

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: default avatarRuan Jinjie <ruanjinjie@huawei.com>
Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
parent 2ccdd1b1
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -2232,8 +2232,7 @@ int register_kretprobe(struct kretprobe *rp)
		return -ENOMEM;

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

	rp->rph->rp = rp;
	for (i = 0; i < rp->maxactive; i++) {
		inst = kzalloc(sizeof(struct kretprobe_instance) +
			       rp->data_size, GFP_KERNEL);
		inst = kzalloc(struct_size(inst, data, rp->data_size), GFP_KERNEL);
		if (inst == NULL) {
			refcount_set(&rp->rph->ref, i);
			free_rp_inst(rp);