From: Eric Paris <eparis@redhat.com>
To: dave@linux.vnet.ibm.com
Cc: steffen.klassert@secunet.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov,
sds@tycho.nsa.gov
Subject: [PATCH 2/3] flex_arrays: allow zero length flex arrays
Date: Mon, 25 Apr 2011 21:45:37 -0400 [thread overview]
Message-ID: <20110426014537.1740.68472.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20110426014531.1740.24077.stgit@paris.rdu.redhat.com>
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.
Based-on-patch-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
---
lib/flex_array.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 0c33b24..2554a5f 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,
unsigned int end;
struct flex_array_part *part;
+ if (!fa->total_nr_elements && !start)
+ 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++) {
next prev parent reply other threads:[~2011-04-26 1:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-26 1:45 [PATCH 1/3] flex_array: flex_array_prealloc takes a number of elements, not an end Eric Paris
2011-04-26 1:45 ` Eric Paris [this message]
2011-04-26 18:57 ` [PATCH 2/3] flex_arrays: allow zero length flex arrays Andrew Morton
2011-04-26 20:38 ` Dave Hansen
2011-04-26 20:44 ` Eric Paris
2011-04-26 1:45 ` [PATCH 3/3] flex_array: allow 0 length elements Eric Paris
2011-04-26 18:57 ` Andrew Morton
2011-04-26 20:46 ` Dave Hansen
2011-04-26 18:56 ` [PATCH 1/3] flex_array: flex_array_prealloc takes a number of elements, not an end Andrew Morton
2011-04-26 19:06 ` Eric Paris
2011-04-26 20:32 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110426014537.1740.68472.stgit@paris.rdu.redhat.com \
--to=eparis@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dave@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome