lkml.org 
[lkml]   [2012]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectUninline kcalloc
    On Tue, 14 Feb 2012, Xi Wang wrote:

    > On Feb 14, 2012, at 11:34 AM, Christoph Lameter wrote:
    > > You can if you check the results later. A zero size return would be an
    > > indication of an error. No need to pass it on to kmalloc.
    >
    > Maybe I misunderstood something here. How do you not pass it to
    > kmalloc() with kmalloc(SAFE_ARRAY_SIZE(n, size), ...)?

    Ok two patches to address this. First one

    Subject: Uninline kcalloc

    kcalloc is not used in performance critical ways. So it does not need to
    be inline. If we would add diagnostics to track the overflow occurrences
    then such code would be replicated at all call sites in the kernel.

    Signed-off-by: Christoph Lameter <cl@linux.com>


    ---
    include/linux/slab.h | 7 +------
    mm/util.c | 15 +++++++++++++++
    2 files changed, 16 insertions(+), 6 deletions(-)

    Index: linux-2.6/include/linux/slab.h
    ===================================================================
    --- linux-2.6.orig/include/linux/slab.h 2012-02-14 09:56:08.000000000 -0600
    +++ linux-2.6/include/linux/slab.h 2012-02-14 13:32:43.000000000 -0600
    @@ -240,12 +240,7 @@ size_t ksize(const void *);
    * for general use, and so are not documented here. For a full list of
    * potential flags, always refer to linux/gfp.h.
    */
    -static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
    -{
    - if (size != 0 && n > ULONG_MAX / size)
    - return NULL;
    - return __kmalloc(n * size, flags | __GFP_ZERO);
    -}
    +void *kcalloc(size_t n, size_t size, gfp_t flags);

    #if !defined(CONFIG_NUMA) && !defined(CONFIG_SLOB)
    /**
    Index: linux-2.6/mm/util.c
    ===================================================================
    --- linux-2.6.orig/mm/util.c 2012-02-14 09:56:08.000000000 -0600
    +++ linux-2.6/mm/util.c 2012-02-14 13:32:54.000000000 -0600
    @@ -75,6 +75,21 @@ void *kmemdup(const void *src, size_t le
    EXPORT_SYMBOL(kmemdup);

    /**
    + * kcalloc - allocate memory for an array. The memory is set to zero.
    + *
    + * @n: number of elements.
    + * @size: element size.
    + * @flags: the type of memory to allocate.
    + */
    +void *kcalloc(size_t n, size_t size, gfp_t flags)
    +{
    + if (size != 0 && n > ULONG_MAX / size)
    + return NULL;
    + return __kmalloc(n * size, flags | __GFP_ZERO);
    +}
    +EXPORT_SYMBOL(kcalloc);
    +
    +/**
    * memdup_user - duplicate memory region from user space
    *
    * @src: source address in user space

    \
     
     \ /
      Last update: 2012-02-14 20:35    [W:0.027 / U:0.240 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site