aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/resource.c')
-rw-r--r--kernel/resource.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index e68cd7477c40..03c897f7935e 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -321,35 +321,37 @@ static int find_resource(struct resource *root, struct resource *new,
321 void *alignf_data) 321 void *alignf_data)
322{ 322{
323 struct resource *this = root->child; 323 struct resource *this = root->child;
324 struct resource tmp = *new;
324 325
325 new->start = root->start; 326 tmp.start = root->start;
326 /* 327 /*
327 * Skip past an allocated resource that starts at 0, since the assignment 328 * Skip past an allocated resource that starts at 0, since the assignment
328 * of this->start - 1 to new->end below would cause an underflow. 329 * of this->start - 1 to tmp->end below would cause an underflow.
329 */ 330 */
330 if (this && this->start == 0) { 331 if (this && this->start == 0) {
331 new->start = this->end + 1; 332 tmp.start = this->end + 1;
332 this = this->sibling; 333 this = this->sibling;
333 } 334 }
334 for(;;) { 335 for(;;) {
335 if (this) 336 if (this)
336 new->end = this->start - 1; 337 tmp.end = this->start - 1;
337 else 338 else
338 new->end = root->end; 339 tmp.end = root->end;
339 if (new->start < min) 340 if (tmp.start < min)
340 new->start = min; 341 tmp.start = min;
341 if (new->end > max) 342 if (tmp.end > max)
342 new->end = max; 343 tmp.end = max;
343 new->start = ALIGN(new->start, align); 344 tmp.start = ALIGN(tmp.start, align);
344 if (alignf) 345 if (alignf)
345 alignf(alignf_data, new, size, align); 346 alignf(alignf_data, &tmp, size, align);
346 if (new->start < new->end && new->end - new->start >= size - 1) { 347 if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) {
347 new->end = new->start + size - 1; 348 new->start = tmp.start;
349 new->end = tmp.start + size - 1;
348 return 0; 350 return 0;
349 } 351 }
350 if (!this) 352 if (!this)
351 break; 353 break;
352 new->start = this->end + 1; 354 tmp.start = this->end + 1;
353 this = this->sibling; 355 this = this->sibling;
354 } 356 }
355 return -EBUSY; 357 return -EBUSY;