* Re: [PATCH -next] kernel: kprobes: Use struct_size()
2023-07-25 19:54 [PATCH -next] kernel: kprobes: Use struct_size() Ruan Jinjie
@ 2023-07-25 13:08 ` Masami Hiramatsu
0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2023-07-25 13:08 UTC (permalink / raw)
To: Ruan Jinjie
Cc: naveen.n.rao, anil.s.keshavamurthy, davem, linux-kernel,
linux-trace-kernel
On Tue, 25 Jul 2023 19:54:24 +0000
Ruan Jinjie <ruanjinjie@huawei.com> wrote:
> Use struct_size() instead of hand-writing it, when allocating a structure
> with a flex array.
>
> This is less verbose.
>
Looks goo to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> kernel/kprobes.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 1fc6095d502d..1d749a917b59 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2220,8 +2220,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;
> @@ -2244,8 +2243,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);
> --
> 2.34.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH -next] kernel: kprobes: Use struct_size()
@ 2023-07-25 19:54 Ruan Jinjie
2023-07-25 13:08 ` Masami Hiramatsu
0 siblings, 1 reply; 2+ messages in thread
From: Ruan Jinjie @ 2023-07-25 19:54 UTC (permalink / raw)
To: naveen.n.rao, anil.s.keshavamurthy, davem, mhiramat, linux-kernel,
linux-trace-kernel
Cc: ruanjinjie
Use struct_size() instead of hand-writing it, when allocating a structure
with a flex array.
This is less verbose.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
kernel/kprobes.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 1fc6095d502d..1d749a917b59 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2220,8 +2220,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;
@@ -2244,8 +2243,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);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-25 13:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25 19:54 [PATCH -next] kernel: kprobes: Use struct_size() Ruan Jinjie
2023-07-25 13:08 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).