aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2011-04-28 15:55:52 -0400
committerEric Paris <eparis@redhat.com>2011-04-28 15:56:07 -0400
commit150cdf6ec0ede8d9f102f1817212447727dcf08c (patch)
tree4044554d4a6824c3ca9a13cad911019b21b8e9d2
parent5a3ea8782c63d3501cb764c176f153c0d9a400e1 (diff)
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: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Eric Paris <eparis@redhat.com> Tested-by: Chris Richards <gizmo@giz-works.com> Cc: stable@kernel.org [2.6.38+]
-rw-r--r--lib/flex_array.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 0c33b24498ba..854b57bd7d9d 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -253,9 +253,16 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
253 unsigned int end; 253 unsigned int end;
254 struct flex_array_part *part; 254 struct flex_array_part *part;
255 255
256 if (!start && !nr_elements)
257 return 0;
258 if (start >= fa->total_nr_elements)
259 return -ENOSPC;
260 if (!nr_elements)
261 return 0;
262
256 end = start + nr_elements - 1; 263 end = start + nr_elements - 1;
257 264
258 if (start >= fa->total_nr_elements || end >= fa->total_nr_elements) 265 if (end >= fa->total_nr_elements)
259 return -ENOSPC; 266 return -ENOSPC;
260 if (elements_fit_in_base(fa)) 267 if (elements_fit_in_base(fa))
261 return 0; 268 return 0;
@@ -346,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
346 int part_nr; 353 int part_nr;
347 int ret = 0; 354 int ret = 0;
348 355
356 if (!fa->total_nr_elements)
357 return 0;
349 if (elements_fit_in_base(fa)) 358 if (elements_fit_in_base(fa))
350 return ret; 359 return ret;
351 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { 360 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) {