Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Jan 2018 10:02:34 -0800 (PST)
From:      "Rodney W. Grimes" <freebsd@pdx.rh.CN85.dnsmgr.net>
To:        Kristof Provost <kp@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r327676 - head/sys/compat/linuxkpi/common/include/linux
Message-ID:  <201801071802.w07I2YEB017699@pdx.rh.CN85.dnsmgr.net>
In-Reply-To: <201801071339.w07DdCaX070032@repo.freebsd.org>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
[ Charset UTF-8 unsupported, converting... ]
> Author: kp
> Date: Sun Jan  7 13:39:12 2018
> New Revision: 327676
> URL: https://svnweb.freebsd.org/changeset/base/327676
> 
> Log:
>   linuxkpi: Implement kcalloc() based on mallocarray()
>   
>   This means we now get integer overflow protection, which Linux code
>   might expect as it is also provided by kcalloc() in Linux.
> 
> Modified:
>   head/sys/compat/linuxkpi/common/include/linux/slab.h
> 
> Modified: head/sys/compat/linuxkpi/common/include/linux/slab.h
> ==============================================================================
> --- head/sys/compat/linuxkpi/common/include/linux/slab.h	Sun Jan  7 13:35:15 2018	(r327675)
> +++ head/sys/compat/linuxkpi/common/include/linux/slab.h	Sun Jan  7 13:39:12 2018	(r327676)
> @@ -46,7 +46,6 @@ MALLOC_DECLARE(M_KMALLOC);
>  #define	kzalloc(size, flags)		kmalloc(size, (flags) | __GFP_ZERO)
>  #define	kzalloc_node(size, flags, node)	kmalloc(size, (flags) | __GFP_ZERO)
>  #define	kfree_const(ptr)		kfree(ptr)
> -#define	kcalloc(n, size, flags)	        kmalloc((n) * (size), (flags) | __GFP_ZERO)

Would not:
#define	kcalloc(n, size, flags)	        mallocarray(mallocarray((n), (size), M_KMALLOC, linux_check_m_flags((flags | __GFP_ZERO))
work just fine, saving a call and stack use of about framesize + 32 bytes?


>  #define	vzalloc(size)			__vmalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 0)
>  #define	vfree(arg)			kfree(arg)
>  #define	kvfree(arg)			kfree(arg)
> @@ -98,6 +97,13 @@ static inline void *
>  kmalloc(size_t size, gfp_t flags)
>  {
>  	return (malloc(size, M_KMALLOC, linux_check_m_flags(flags)));
> +}
> +
> +static inline void *
> +kcalloc(size_t n, size_t size, gfp_t flags)
> +{
> +	flags |= __GFP_ZERO;
> +	return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags)));
>  }
>  
>  static inline void *
> 
> 

-- 
Rod Grimes                                                 rgrimes@freebsd.org



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?201801071802.w07I2YEB017699>