xen/common: Introduce xrealloc_flex_struct() helper macros
authorOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Thu, 26 Sep 2019 11:20:30 +0000 (14:20 +0300)
committerJulien Grall <julien.grall@arm.com>
Thu, 26 Sep 2019 13:35:32 +0000 (14:35 +0100)
commitefc882ffb762a0b2eeadb60ea05a1093b5a48de8
tree49a0c7b1c081fc64fffad451989ab87f18d17872
parent50879e805edb363c3cfa860af86b4b854be53641
xen/common: Introduce xrealloc_flex_struct() helper macros

This patch introduces type-safe helper macros to re-allocate space
for a structure with a flexible array of typed objects.

For example, if we need to re-size the "data" array:

   struct arrlen
   {
      size_t len;
      int data[];
   };

We can use the proposed macros in the following way:

   new_ptr = realloc_flex_struct(old_ptr, data, nr_elem);

where nr_elem is the desired number of elements.

Subsequent patch will use this macros.

Also, while here, introduce xmalloc(xzalloc)_flex_struct() to
allocate space for a structure with a flexible array of typed objects.

Suggested-by: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>
CC: George Dunlap <George.Dunlap@eu.citrix.com>
CC: Ian Jackson <ian.jackson@eu.citrix.com>
CC: Julien Grall <julien.grall@arm.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Tim Deegan <tim@xen.org>
CC: Wei Liu <wl@xen.org>
xen/include/xen/xmalloc.h