[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-edac
Subject: Re: [PATCH 1/8] mm: slab: provide krealloc_array()
From: Mike Rapoport <rppt () kernel ! org>
Date: 2020-10-28 8:47:03
Message-ID: 20201028084703.GC1428094 () kernel ! org
[Download RAW message or body]
On Tue, Oct 27, 2020 at 01:17:18PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> When allocating an array of elements, users should check for
> multiplication overflow or preferably use one of the provided helpers
> like: kmalloc_array().
>
> There's no krealloc_array() counterpart but there are many users who use
> regular krealloc() to reallocate arrays. Let's provide an actual
> krealloc_array() implementation.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
> include/linux/slab.h | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index dd6897f62010..0e6683affee7 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -592,6 +592,17 @@ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
> return __kmalloc(bytes, flags);
> }
>
Can you please add kernel-doc here and a word or two about this function
to Documentation/core-api/memory-allocation.rst?
> +static __must_check inline void *
> +krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t flags)
> +{
> + size_t bytes;
> +
> + if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
> + return NULL;
> +
> + return krealloc(p, bytes, flags);
> +}
> +
> /**
> * kcalloc - allocate memory for an array. The memory is set to zero.
> * @n: number of elements.
> --
> 2.29.1
>
>
--
Sincerely yours,
Mike.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic