return best;
}
-static struct drm_mm_node *find_hole(struct drm_mm *mm, u64 addr)
+static struct drm_mm_node *find_hole_addr(struct drm_mm *mm, u64 addr, u64 size)
{
struct rb_node *rb = mm->holes_addr.rb_node;
struct drm_mm_node *node = NULL;
while (rb) {
u64 hole_start;
+ if (rb_hole_addr_to_node(rb)->subtree_max_hole < size)
+ break;
+
node = rb_hole_addr_to_node(rb);
hole_start = __drm_mm_hole_node_start(node);
return best_hole(mm, size);
case DRM_MM_INSERT_LOW:
- return find_hole(mm, start);
+ return find_hole_addr(mm, start, size);
case DRM_MM_INSERT_HIGH:
- return find_hole(mm, end);
+ return find_hole_addr(mm, end, size);
case DRM_MM_INSERT_EVICT:
return list_first_entry_or_null(&mm->hole_stack,
return -ENOSPC;
/* Find the relevant hole to add our node to */
- hole = find_hole(mm, node->start);
+ hole = find_hole_addr(mm, node->start, 0);
if (!hole)
return -ENOSPC;
}
memset(&node, 0, sizeof(node));
- err = drm_mm_insert_node_generic(&mm, &node,
- 2, 0, 0,
- mode | DRM_MM_INSERT_ONCE);
- if (!err) {
- pr_err("Unexpectedly inserted the node into the wrong hole: node.start=%llx\n",
- node.start);
- err = -EINVAL;
- goto err_node;
- }
-
err = drm_mm_insert_node_generic(&mm, &node, 2, 0, 0, mode);
if (err) {
pr_err("Could not insert the node into the available hole!\n");
goto err_hi;
}
-err_node:
drm_mm_remove_node(&node);
err_hi:
drm_mm_remove_node(&rsvd_hi);