flex_array: convert element_nr formals to unsigned
authorDavid Rientjes <rientjes@google.com>
Wed, 26 Aug 2009 21:29:22 +0000 (14:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 27 Aug 2009 03:06:52 +0000 (20:06 -0700)
commitb62e408c05228f40e69bb38a48db8961cac6cd23
tree40711bad4a60adb8f331d71574ec61e13c5a352d
parent8e7ee27095aee87b5db1b0061e2ceea5878a1bbd
flex_array: convert element_nr formals to unsigned

It's problematic to allow signed element_nr's or total's to be passed as
part of the flex array API.

flex_array_alloc() allows total_nr_elements to be set to a negative
quantity, which is obviously erroneous.

flex_array_get() and flex_array_put() allows negative array indices in
dereferencing an array part, which could address memory mapped before
struct flex_array.

The fix is to convert all existing element_nr formals to be qualified as
unsigned.  Existing checks to compare it to total_nr_elements or the max
array size based on element_size need not be changed.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/flex_array.h
lib/flex_array.c