Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/mm: Fix search for smallest hole satisfying constraints

entry->size is the size of the node, not the size of the hole after it.
So the code would actually find the hole which can satisfy the
constraints and which is preceded by the smallest node, not the smallest
hole satisfying the constraints.

Reported-by: "Huang, FrankR" <FrankR.Huang@amd.com>
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

authored by

Michel Dänzer and committed by
Dave Airlie
145bccd2 740c22ae

+8 -4
+8 -4
drivers/gpu/drm/drm_mm.c
··· 423 423 424 424 __drm_mm_for_each_hole(entry, mm, adj_start, adj_end, 425 425 flags & DRM_MM_SEARCH_BELOW) { 426 + unsigned long hole_size = adj_end - adj_start; 427 + 426 428 if (mm->color_adjust) { 427 429 mm->color_adjust(entry, color, &adj_start, &adj_end); 428 430 if (adj_end <= adj_start) ··· 437 435 if (!(flags & DRM_MM_SEARCH_BEST)) 438 436 return entry; 439 437 440 - if (entry->size < best_size) { 438 + if (hole_size < best_size) { 441 439 best = entry; 442 - best_size = entry->size; 440 + best_size = hole_size; 443 441 } 444 442 } 445 443 ··· 467 465 468 466 __drm_mm_for_each_hole(entry, mm, adj_start, adj_end, 469 467 flags & DRM_MM_SEARCH_BELOW) { 468 + unsigned long hole_size = adj_end - adj_start; 469 + 470 470 if (adj_start < start) 471 471 adj_start = start; 472 472 if (adj_end > end) ··· 486 482 if (!(flags & DRM_MM_SEARCH_BEST)) 487 483 return entry; 488 484 489 - if (entry->size < best_size) { 485 + if (hole_size < best_size) { 490 486 best = entry; 491 - best_size = entry->size; 487 + best_size = hole_size; 492 488 } 493 489 } 494 490