aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/resource.c')
-rw-r--r--kernel/resource.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index 3ff40178dce..c8dc249da5c 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -419,6 +419,9 @@ static int __find_resource(struct resource *root, struct resource *old,
419 else 419 else
420 tmp.end = root->end; 420 tmp.end = root->end;
421 421
422 if (tmp.end < tmp.start)
423 goto next;
424
422 resource_clip(&tmp, constraint->min, constraint->max); 425 resource_clip(&tmp, constraint->min, constraint->max);
423 arch_remove_reservations(&tmp); 426 arch_remove_reservations(&tmp);
424 427
@@ -436,8 +439,10 @@ static int __find_resource(struct resource *root, struct resource *old,
436 return 0; 439 return 0;
437 } 440 }
438 } 441 }
439 if (!this) 442
443next: if (!this || this->end == root->end)
440 break; 444 break;
445
441 if (this != old) 446 if (this != old)
442 tmp.start = this->end + 1; 447 tmp.start = this->end + 1;
443 this = this->sibling; 448 this = this->sibling;
@@ -553,6 +558,27 @@ int allocate_resource(struct resource *root, struct resource *new,
553 558
554EXPORT_SYMBOL(allocate_resource); 559EXPORT_SYMBOL(allocate_resource);
555 560
561/**
562 * lookup_resource - find an existing resource by a resource start address
563 * @root: root resource descriptor
564 * @start: resource start address
565 *
566 * Returns a pointer to the resource if found, NULL otherwise
567 */
568struct resource *lookup_resource(struct resource *root, resource_size_t start)
569{
570 struct resource *res;
571
572 read_lock(&resource_lock);
573 for (res = root->child; res; res = res->sibling) {
574 if (res->start == start)
575 break;
576 }
577 read_unlock(&resource_lock);
578
579 return res;
580}
581
556/* 582/*
557 * Insert a resource into the resource tree. If successful, return NULL, 583 * Insert a resource into the resource tree. If successful, return NULL,
558 * otherwise return the conflicting resource (compare to __request_resource()) 584 * otherwise return the conflicting resource (compare to __request_resource())