[PATCH] drm: Use a common test for no holes before find_hole

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/drm_mm.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 89df9e51f21d..73b9137797e4 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -276,7 +276,7 @@ static struct drm_mm_node *best_hole(struct drm_mm *mm, u64 size)
 	struct drm_mm_node *best = NULL;
 	struct rb_node *rb = mm->holes_size.rb_node;
 
-	while (rb) {
+	do {
 		struct drm_mm_node *pos =
 			rb_entry(rb, struct drm_mm_node, rb_hole_size);
 		u64 sz = pos->hole_size;
@@ -289,17 +289,17 @@ static struct drm_mm_node *best_hole(struct drm_mm *mm, u64 size)
 		} else {
 			return pos;
 		}
-	}
+	} while (rb);
 
 	return best;
 }
 
 static struct drm_mm_node *find_hole(struct drm_mm *mm, u64 addr)
 {
-	struct drm_mm_node *node = NULL;
+	struct drm_mm_node *node;
 	struct rb_node *rb = mm->holes_addr.rb_node;
 
-	while (rb) {
+	do {
 		u64 hole_start;
 
 		node = rb_hole_addr_to_node(rb);
@@ -311,7 +311,7 @@ static struct drm_mm_node *find_hole(struct drm_mm *mm, u64 addr)
 			rb = node->rb_hole_addr.rb_right;
 		else
 			break;
-	}
+	} while (rb);
 
 	return node;
 }
@@ -336,9 +336,9 @@ first_hole(struct drm_mm *mm,
 		return find_hole(mm, end);
 
 	case DRM_MM_INSERT_EVICT:
-		return list_first_entry_or_null(&mm->hole_stack,
-						struct drm_mm_node,
-						hole_stack);
+		return list_first_entry(&mm->hole_stack,
+					struct drm_mm_node,
+					hole_stack);
 	}
 }
 
@@ -389,6 +389,9 @@ int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node)
 	if (unlikely(end <= node->start))
 		return -ENOSPC;
 
+	if (RB_EMPTY_ROOT(&mm->holes_addr))
+		return -ENOSPC;
+
 	/* Find the relevant hole to add our node to */
 	hole = find_hole(mm, node->start);
 	if (!hole)
-- 
2.11.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux