[Intel-gfx] [PATCH v5] drm/i915/gtt: Avoid calling kcalloc in a loop when allocating temp bitmaps

Daniel Vetter daniel at ffwll.ch
Fri Sep 4 00:53:58 PDT 2015


On Thu, Sep 03, 2015 at 09:48:03PM +0100, Chris Wilson wrote:
> On Thu, Sep 03, 2015 at 07:22:18PM +0200, MichaƂ Winiarski wrote:
> > +	pts = kcalloc(pdpes * BITS_TO_LONGS(I915_PDES),
> > +		      sizeof(unsigned long), GFP_TEMPORARY);
> 
> Something to remember is that kcalloc is written presuming that the size
> argument (the second) is constant.
> 
> pts = kcalloc(pdpes,
> 	      BITS_TO_LONGS(I915_PDES) * sizeof(unsigned long),
> 	      GFP_TEMPORARY);
> 
> should be infinitesimally more efficient.

That's also better style from a security pov sinc kcalloc checks for
overflows. Which means if you multiply yourself things might overflow and
go boom. Luckily pdpdes is guaranteed to be small enough here, but still
secure coding best practices means you better not multiply the variable.
Hence I changed this.

> Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

Queued for -next, thanks for the patch.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the Intel-gfx mailing list