• Eric Paris's avatar
    flex_array: allow 0 length elements · a8d05c81
    Eric Paris authored
    flex_arrays are supposed to be a replacement for:
    kmalloc(num_elements * sizeof(element))
    
    If kmalloc is given 0 num_elements or a 0 size element it will happily return
    ZERO_SIZE_PTR.  Which looks like a valid allocation, but which will explode if
    something actually try to use it.  The current flex_array code will return an
    equivalent result if num_elements is 0, but will fail to work if
    sizeof(element) is 0.  This patch allows allocation to work even for 0 size
    elements.  It will cause flex_arrays to explode though if they are used.
    Imitating the kmalloc behavior.
    Based-on-patch-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: default avatarEric Paris <eparis@redhat.com>
    Acked-by: default avatarDave Hansen <dave@linux.vnet.ibm.com>
    a8d05c81
flex_array.c 10.6 KB