[dpdk-dev] [PATCH] eal/rte_malloc: add alloc_size() attribute to allocation functions

Burakov, Anatoly anatoly.burakov at intel.com
Mon Sep 14 17:35:58 CEST 2020


On 04-Sep-20 11:11 PM, Stephen Hemminger wrote:
> By using the alloc_size() attribute the compiler can optimize
> better and detect errors at compile time.
> 
> For example, Gcc will fail one of the invalid allocation examples
> in app/test/test_malloc.c because the allocation is outside the
> limits of memory.
> 
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---

This is a very cool feature! LGTM

Acked-by: Anatoly Burakov <anatoly.burakov at intel.com>

>   void *
> -rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket);
> +rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
> +	__rte_alloc_size(2);
>   
>   /**
>    * Replacement function for calloc(), using huge-page memory. Memory area is
> @@ -239,9 +243,9 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket);
>    *     align is not a power of two).
>    *   - Otherwise, the pointer to the allocated object.
>    */
> -__rte_malloc
>   void *

Where did this come from?

> -rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket);
> +rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket)
> +	__rte_alloc_size(2, 3);
>   
>   /**
>    * Frees the memory space pointed to by the provided pointer.
> 


-- 
Thanks,
Anatoly


More information about the dev mailing list