Skip to content
Snippets Groups Projects
Commit 150cdf6e authored by Eric Paris's avatar Eric Paris
Browse files

flex_arrays: allow zero length flex arrays


Just like kmalloc will allow one to allocate a 0 length segment of memory
flex arrays should do the same thing.  It should bomb if you try to use
something, but it should at least allow the allocation.

This is needed because when SELinux switched to using flex_arrays in 2.6.38
the inability to allocate a 0 length array resulted in SELinux policy load
returning -ENOSPC when previously it worked.

Based-on-patch-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
Tested-by: default avatarChris Richards <gizmo@giz-works.com>
Cc: stable@kernel.org [2.6.38+]
parent 5a3ea878
No related branches found
No related tags found
No related merge requests found
......@@ -253,9 +253,16 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
unsigned int end;
struct flex_array_part *part;
if (!start && !nr_elements)
return 0;
if (start >= fa->total_nr_elements)
return -ENOSPC;
if (!nr_elements)
return 0;
end = start + nr_elements - 1;
if (start >= fa->total_nr_elements || end >= fa->total_nr_elements)
if (end >= fa->total_nr_elements)
return -ENOSPC;
if (elements_fit_in_base(fa))
return 0;
......@@ -346,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
int part_nr;
int ret = 0;
if (!fa->total_nr_elements)
return 0;
if (elements_fit_in_base(fa))
return ret;
for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment