提交 6259a56b 编写于 作者: C Chris Wilson 提交者: Daniel Vetter

drm: Add asserts to catch overflow in drm_mm_init() and drm_mm_init_scan()

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: NChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: NJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161222083641.2691-26-chris@chris-wilson.co.uk
上级 ac9bb7b7
...@@ -729,6 +729,8 @@ void drm_mm_init_scan(struct drm_mm *mm, ...@@ -729,6 +729,8 @@ void drm_mm_init_scan(struct drm_mm *mm,
u64 alignment, u64 alignment,
unsigned long color) unsigned long color)
{ {
DRM_MM_BUG_ON(!size);
mm->scan_color = color; mm->scan_color = color;
mm->scan_alignment = alignment; mm->scan_alignment = alignment;
mm->scan_size = size; mm->scan_size = size;
...@@ -764,6 +766,9 @@ void drm_mm_init_scan_with_range(struct drm_mm *mm, ...@@ -764,6 +766,9 @@ void drm_mm_init_scan_with_range(struct drm_mm *mm,
u64 start, u64 start,
u64 end) u64 end)
{ {
DRM_MM_BUG_ON(start >= end);
DRM_MM_BUG_ON(!size || size > end - start);
mm->scan_color = color; mm->scan_color = color;
mm->scan_alignment = alignment; mm->scan_alignment = alignment;
mm->scan_size = size; mm->scan_size = size;
...@@ -882,6 +887,8 @@ EXPORT_SYMBOL(drm_mm_scan_remove_block); ...@@ -882,6 +887,8 @@ EXPORT_SYMBOL(drm_mm_scan_remove_block);
*/ */
void drm_mm_init(struct drm_mm *mm, u64 start, u64 size) void drm_mm_init(struct drm_mm *mm, u64 start, u64 size)
{ {
DRM_MM_BUG_ON(start + size <= start);
INIT_LIST_HEAD(&mm->hole_stack); INIT_LIST_HEAD(&mm->hole_stack);
mm->scanned_blocks = 0; mm->scanned_blocks = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册