lkml.org 
[lkml]   [2011]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] flex_array: Change behaviour on zero size allocations
On Mon, Jan 31, 2011 at 08:31:37AM -0800, Dave Hansen wrote:
>
> 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.
>

Both objections are correct, I'll send an updated patch.

Steffen


\
 
 \ /
  Last update: 2011-02-01 11:27    [W:0.047 / U:5.276 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site