From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: <naveen.n.rao@linux.ibm.com>, <anil.s.keshavamurthy@intel.com>,
<davem@davemloft.net>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH -next] kernel: kprobes: Use struct_size()
Date: Tue, 25 Jul 2023 22:08:05 +0900 [thread overview]
Message-ID: <20230725220805.af340161a7c620a33750fda2@kernel.org> (raw)
In-Reply-To: <20230725195424.3469242-1-ruanjinjie@huawei.com>
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>
prev parent reply other threads:[~2023-07-25 13:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 19:54 Ruan Jinjie
2023-07-25 13:08 ` Masami Hiramatsu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230725220805.af340161a7c620a33750fda2@kernel.org \
--to=mhiramat@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=ruanjinjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®