lkml.org 
[lkml]   [2005]   [Aug]   [15]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
FromDenis Vlasenko <>
SubjectRe: [-mm patch] make kcalloc() a static inline
DateMon, 15 Aug 2005 11:20:46 +0300
On Monday 15 August 2005 11:14, Arjan van de Ven wrote:
> On Mon, 2005-08-15 at 11:06 +0300, Denis Vlasenko wrote:
> 
> > > +static inline void *kcalloc(size_t n, size_t size, unsigned int __nocast flags)
> > > +{
> > > +	if (n != 0 && size > INT_MAX / n)
> > > +		return NULL;
> > > +	return kzalloc(n * size, flags);
> > > +}
> 
> > Can you conditionalize it on __builtin_constant_p(n) ?
> > Otherwise with variable n you have 3 oprations in inlined
> > code, one of them a division.
> 
> you can't conditionalize the security check really. If it's constant,
> gcc will optimize it anyway, and if it's not constant you for sure want
> the check there...

Sure, I don't want to disable the check. I want that check to be
in _non-inlined function_.

static inline void *kcalloc(size_t n, size_t size, unsigned int __nocast flags)
{
	if (__builtin_constant_p(n)) {
		if (n != 0 && size > INT_MAX / n)
			return NULL;
		return kzalloc(n * size, flags);
	}
	return kcalloc_helper(n, size, flags);
}
void *kcalloc_helper(size_t n, size_t size, unsigned int __nocast flags)
{
	if (n != 0 && size > INT_MAX / n)
		return NULL;
	return kzalloc(n * size, flags);
}
--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-08-15 10:23    [from the cache]
©2003-2008