[Intel-gfx] [PATCH v2 27/40] drm: Add asserts to catch overflow in drm_mm_init() and drm_mm_init_scan()

Joonas Lahtinen joonas.lahtinen at linux.intel.com
Fri Dec 16 13:10:12 UTC 2016


On pe, 2016-12-16 at 07:47 +0000, Chris Wilson wrote:
> A simple assert to ensure that we don't overflow start + size when
> initialising the drm_mm, or its scanner.
> 
> In future, we may want to switch to tracking the value of ranges (rather
> than size) so that we can cover the full u64, for example like resource
> tracking.
> 
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

<SNIP>

> @@ -729,6 +729,8 @@ void drm_mm_init_scan(struct drm_mm *mm,
>  		      u64 alignment,
>  		      unsigned long color)
>  {
> +	DRM_MM_BUG_ON(size == 0);

Nitpicking, DIM will complain that this should be !size.

> +
> >  	mm->scan_color = color;
> >  	mm->scan_alignment = alignment;
> >  	mm->scan_size = size;
> @@ -764,6 +766,9 @@ void drm_mm_init_scan_with_range(struct drm_mm *mm,
>  				 u64 start,
>  				 u64 end)
>  {

Ditto, could have simply DRM_MM_BUG_ON(!size);

Reviewed-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>

Regards, Joonas

> +	DRM_MM_BUG_ON(start >= end);
> +	DRM_MM_BUG_ON(size == 0 || size > end - start);
> +
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation


More information about the Intel-gfx mailing list