From: Dave Hansen <dave@linux.vnet.ibm.com>
To: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Eric Paris <eparis@redhat.com>,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH] flex_array: Change behaviour on zero size allocations
Date: Mon, 31 Jan 2011 08:31:37 -0800 [thread overview]
Message-ID: <1296491497.7797.3792.camel@nimitz> (raw)
In-Reply-To: <20110131085213.GK3070@secunet.com>
On Mon, 2011-01-31 at 09:52 +0100, Steffen Klassert wrote:
> int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
> gfp_t flags)
> {
> - int part_nr = fa_element_to_part_nr(fa, element_nr);
> + int part_nr;
> struct flex_array_part *part;
> void *dst;
>
> + if (!fa->element_size)
> + return 0;
> if (element_nr >= fa->total_nr_elements)
> return -ENOSPC;
I think this still has some of the issues of the earlier patch. The
zero-size check needs to be moved after the ->total_nr_elements check.
Otherwise, this won't produce any errors:
fa = flex_array_alloc(0, 100, GFP_KERNEL);
flex_array_put(fa, 1001, ptr, GFP_KERNEL);
> @@ -284,6 +297,8 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr)
> int part_nr = fa_element_to_part_nr(fa, element_nr);
> struct flex_array_part *part;
>
> + if (!fa->total_nr_elements || !fa->element_size)
> + return NULL;
> if (element_nr >= fa->total_nr_elements)
> return NULL;
> if (elements_fit_in_base(fa))
Do you really need to check fa->total_nr_elements both for zero and
against element_nr? Seems a but superfluous to me.
-- Dave
next prev parent reply other threads:[~2011-01-31 16:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-31 8:52 [PATCH] flex_array: Change behaviour on zero size allocations Steffen Klassert
2011-01-31 16:31 ` Dave Hansen [this message]
2011-02-01 10:24 ` Steffen Klassert
2011-02-01 11:03 ` Steffen Klassert
2011-02-01 14:55 ` Dave Hansen
2011-02-01 15:20 ` Eric Paris
2011-02-02 7:55 ` Steffen Klassert
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=1296491497.7797.3792.camel@nimitz \
--to=dave@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.