diff mbox

[1/4] sparc: bpf_jit: Use kmalloc_array() in bpf_jit_compile()

Message ID 259699cf-6fb1-f9e6-f535-fe880a7fa6dc@users.sourceforge.net
State Rejected
Delegated to: David Miller
Headers show

Commit Message

SF Markus Elfring Sept. 3, 2016, 4:36 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 3 Sep 2016 17:10:20 +0200

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/sparc/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel Borkmann Sept. 3, 2016, 4:51 p.m. UTC | #1
On 09/03/2016 06:36 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 3 Sep 2016 17:10:20 +0200
>
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.

When you talk about "issue", could you please explain yourself what
concrete "issue" you were seeing ?!

This particular multiplication here is guaranteed to never overflow,
so at best a minor cleanup if you will.

(Do you actually have a sparc to test out your changes?)

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   arch/sparc/net/bpf_jit_comp.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
> index a6d9204..ced1393 100644
> --- a/arch/sparc/net/bpf_jit_comp.c
> +++ b/arch/sparc/net/bpf_jit_comp.c
> @@ -372,7 +372,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
>   	if (!bpf_jit_enable)
>   		return;
>
> -	addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
> +	addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
>   	if (addrs == NULL)
>   		return;
>
>

--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
index a6d9204..ced1393 100644
--- a/arch/sparc/net/bpf_jit_comp.c
+++ b/arch/sparc/net/bpf_jit_comp.c
@@ -372,7 +372,7 @@  void bpf_jit_compile(struct bpf_prog *fp)
 	if (!bpf_jit_enable)
 		return;
 
-	addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
+	addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
 	if (addrs == NULL)
 		return;