lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20230725220805.af340161a7c620a33750fda2@kernel.org>
Date:   Tue, 25 Jul 2023 22:08:05 +0900
From:   Masami Hiramatsu (Google) <mhiramat@...nel.org>
To:     Ruan Jinjie <ruanjinjie@...wei.com>
Cc:     <naveen.n.rao@...ux.ibm.com>, <anil.s.keshavamurthy@...el.com>,
        <davem@...emloft.net>, <linux-kernel@...r.kernel.org>,
        <linux-trace-kernel@...r.kernel.org>
Subject: Re: [PATCH -next] kernel: kprobes: Use struct_size()

On Tue, 25 Jul 2023 19:54:24 +0000
Ruan Jinjie <ruanjinjie@...wei.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@...nel.org>

Thanks!

> Signed-off-by: Ruan Jinjie <ruanjinjie@...wei.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@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ