Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1470319

Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two functions

From Nicolas Pitre <nicolas.pitre@linaro.org>
Newsgroups linux.kernel
Subject Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two functions
Date 2016-08-25 20:20 +0200
Message-ID <sa7pT-4uc-13@gated-at.bofh.it> (permalink)
References <sa5ev-2Wi-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 25 Aug 2016, SF Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 25 Aug 2016 17:45:23 +0200
> 
> Multiplications for the size determination of memory allocations
> indicated that array data structures 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>

The use of kmalloc_array() introduces a duplicate of the size capping 
check that already exists in the code.  However it seems that gcc is 
smart enough to figure that out and doesn't emit it twice.

Note that I'm not implying that the existing check should be removed if 
this patch is applied though. Having it there makes the code clearer. 
But if this patch makes a Coccinelle script happier then ...

Acked-by: Nicolas Pitre <nico@linaro.org>

> ---
>  arch/arm/kernel/sys_oabi-compat.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c
> index 5f221ac..e624db9 100644
> --- a/arch/arm/kernel/sys_oabi-compat.c
> +++ b/arch/arm/kernel/sys_oabi-compat.c
> @@ -285,7 +285,7 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
>  		return -EINVAL;
>  	if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
>  		return -EFAULT;
> -	kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL);
> +	kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
>  	if (!kbuf)
>  		return -ENOMEM;
>  	fs = get_fs();
> @@ -323,7 +323,7 @@ asmlinkage long sys_oabi_semtimedop(int semid,
>  		return -EINVAL;
>  	if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
>  		return -EFAULT;
> -	sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
> +	sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
>  	if (!sops)
>  		return -ENOMEM;
>  	err = 0;
> -- 
> 2.9.3
> 
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-25 18:00 +0200
  Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two  functions Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-08-25 20:20 +0200
  Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two  functions Russell King - ARM Linux <linux@armlinux.org.uk> - 2016-08-26 01:20 +0200
    Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two  functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-26 15:40 +0200
      Re: [PATCH] arm: sys_oabi-compat: Use kmalloc_array() in two  functions Russell King - ARM Linux <linux@armlinux.org.uk> - 2016-08-26 15:50 +0200
        Re: arm: sys_oabi-compat: Use kmalloc_array() in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-26 17:10 +0200

csiph-web