Messages in this thread | | | Subject | Re: [PATCH] [RESEND] aic7xxx: replace kmalloc/memset by kzalloc | From | Joe Perches <> | Date | Tue, 24 Mar 2015 13:57:02 -0700 |
| |
On Tue, 2015-03-24 at 13:46 -0700, Michael Opdenacker wrote: > Hi, > > On 03/22/2015 11:59 PM, Hannes Reinecke wrote: > > On 03/22/2015 05:31 PM, Michael Opdenacker wrote: > >> This replaces kmalloc + memset by a call to kzalloc > >> (or kcalloc when appropriate, which zeroes memory too) > >> > >> This also fixes one checkpatch.pl issue in the process. > >> > >> This improvement was suggested by "make coccicheck" > >> > >> Signed-off-by: Michael Opdenacker <michael.opdenacker@free-electrons.com> > > Reviewed-by: Hannes Reinecke <hare@suse.de> > > I'm sending a version that reverts the use of kcalloc() instead of > kzalloc(). For reasons I don't understand, I didn't see the end of > Robert Elliott's comment that the use of kcalloc() could prevent the > compiler from detecting an overflow.
I'm confused. I don't see that comment either, but the entire point of kcalloc is to prevent overflows by returning NULL when an overflow might occur.
from include/linux/slab.h:
/** * kmalloc_array - allocate memory for an array. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate (see kmalloc). */ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) { if (size != 0 && n > SIZE_MAX / size) return NULL; return __kmalloc(n * size, flags); }
/** * kcalloc - allocate memory for an array. The memory is set to zero. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate (see kmalloc). */ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) { return kmalloc_array(n, size, flags | __GFP_ZERO); }
| |