summaryrefslogtreecommitdiff
path: root/drivers/gpu/buddy.c
diff options
context:
space:
mode:
authorFrancois Dugast <francois.dugast@intel.com>2026-05-22 11:25:30 +0200
committerFrancois Dugast <francois.dugast@intel.com>2026-05-29 13:44:00 +0200
commite16ac0132f1dcb2ad403de6dbefc2a3881cd5112 (patch)
tree1a181f41e1d0745b3eb3a688fb740c15c79f9c42 /drivers/gpu/buddy.c
parent51d28339bfefe1ed603820669534440465f5dc46 (diff)
downloadlinux-next-e16ac0132f1dcb2ad403de6dbefc2a3881cd5112.tar.gz
linux-next-e16ac0132f1dcb2ad403de6dbefc2a3881cd5112.zip
gpu/buddy: Introduce __gpu_buddy_undo_splits() helper
The pattern of merging a block back with its buddy on error paths is duplicated across multiple locations. Extract it into a __gpu_buddy_undo_splits() helper to avoid repetition and prepare for future changes. Suggested-by: Matthew Auld <matthew.auld@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://lore.kernel.org/r/20260522092600.32818-4-francois.dugast@intel.com Signed-off-by: Francois Dugast <francois.dugast@intel.com>
Diffstat (limited to 'drivers/gpu/buddy.c')
-rw-r--r--drivers/gpu/buddy.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
index 9f6696f47f89..8654604b87a4 100644
--- a/drivers/gpu/buddy.c
+++ b/drivers/gpu/buddy.c
@@ -650,6 +650,19 @@ static bool block_incompatible(struct gpu_buddy_block *block, unsigned int flags
return needs_clear != gpu_buddy_block_is_clear(block);
}
+static void __gpu_buddy_undo_splits(struct gpu_buddy *mm,
+ struct gpu_buddy_block *block)
+{
+ struct gpu_buddy_block *buddy = __get_buddy(block);
+
+ if (buddy &&
+ (gpu_buddy_block_is_free(block) &&
+ gpu_buddy_block_is_free(buddy))) {
+ rbtree_remove(mm, block);
+ __gpu_buddy_free(mm, block, false);
+ }
+}
+
static struct gpu_buddy_block *
__alloc_range_bias(struct gpu_buddy *mm,
u64 start, u64 end,
@@ -659,7 +672,6 @@ __alloc_range_bias(struct gpu_buddy *mm,
{
u64 req_size = mm->chunk_size << order;
struct gpu_buddy_block *block;
- struct gpu_buddy_block *buddy;
LIST_HEAD(dfs);
int err;
int i;
@@ -734,13 +746,7 @@ err_undo:
* bigger is better, so make sure we merge everything back before we
* free the allocated blocks.
*/
- buddy = __get_buddy(block);
- if (buddy &&
- (gpu_buddy_block_is_free(block) &&
- gpu_buddy_block_is_free(buddy))) {
- rbtree_remove(mm, block);
- __gpu_buddy_free(mm, block, false);
- }
+ __gpu_buddy_undo_splits(mm, block);
return ERR_PTR(err);
}
@@ -849,8 +855,7 @@ alloc_from_freetree(struct gpu_buddy *mm,
return block;
err_undo:
- rbtree_remove(mm, block);
- __gpu_buddy_free(mm, block, false);
+ __gpu_buddy_undo_splits(mm, block);
return ERR_PTR(err);
}
@@ -914,7 +919,6 @@ gpu_buddy_offset_aligned_allocation(struct gpu_buddy *mm,
{
struct gpu_buddy_block *block = NULL;
unsigned int order, tmp, alignment;
- struct gpu_buddy_block *buddy;
enum gpu_buddy_free_tree tree;
unsigned long pages;
int err;
@@ -967,13 +971,7 @@ err_undo:
* bigger is better, so make sure we merge everything back before we
* free the allocated blocks.
*/
- buddy = __get_buddy(block);
- if (buddy &&
- (gpu_buddy_block_is_free(block) &&
- gpu_buddy_block_is_free(buddy))) {
- rbtree_remove(mm, block);
- __gpu_buddy_free(mm, block, false);
- }
+ __gpu_buddy_undo_splits(mm, block);
return ERR_PTR(err);
}
@@ -984,7 +982,6 @@ static int __alloc_range(struct gpu_buddy *mm,
u64 *total_allocated_on_err)
{
struct gpu_buddy_block *block;
- struct gpu_buddy_block *buddy;
u64 total_allocated = 0;
LIST_HEAD(allocated);
u64 end;
@@ -1055,13 +1052,7 @@ err_undo:
* bigger is better, so make sure we merge everything back before we
* free the allocated blocks.
*/
- buddy = __get_buddy(block);
- if (buddy &&
- (gpu_buddy_block_is_free(block) &&
- gpu_buddy_block_is_free(buddy))) {
- rbtree_remove(mm, block);
- __gpu_buddy_free(mm, block, false);
- }
+ __gpu_buddy_undo_splits(mm, block);
err_free:
if (err == -ENOSPC && total_allocated_on_err) {