aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/resource.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index 7dc8ad24f915..26e9f2546923 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -365,6 +365,15 @@ static resource_size_t simple_align_resource(void *data,
365 return avail->start; 365 return avail->start;
366} 366}
367 367
368static void resource_clip(struct resource *res, resource_size_t min,
369 resource_size_t max)
370{
371 if (res->start < min)
372 res->start = min;
373 if (res->end > max)
374 res->end = max;
375}
376
368/* 377/*
369 * Find empty slot in the resource tree given range and alignment. 378 * Find empty slot in the resource tree given range and alignment.
370 */ 379 */
@@ -394,10 +403,8 @@ static int find_resource(struct resource *root, struct resource *new,
394 tmp.end = this->start - 1; 403 tmp.end = this->start - 1;
395 else 404 else
396 tmp.end = root->end; 405 tmp.end = root->end;
397 if (tmp.start < min) 406
398 tmp.start = min; 407 resource_clip(&tmp, min, max);
399 if (tmp.end > max)
400 tmp.end = max;
401 tmp.start = ALIGN(tmp.start, align); 408 tmp.start = ALIGN(tmp.start, align);
402 409
403 tmp.start = alignf(alignf_data, &tmp, size, align); 410 tmp.start = alignf(alignf_data, &tmp, size, align);