Resources: insert identical resources above existing resources
If you have two resources which aree exactly the same size, insert_resource() currently inserts the new one below the existing one. This is wrong because there's no way to insert a resource of the same size above an existing one. I took this opportunity to rewrite the initial loop to be a for-loop instead of a goto-loop and fix the documentation. Signed-off-by: Matthew Wilcox <matthew@wil.cx> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
b278240839
commit
d33b6fba2c
1 changed files with 16 additions and 16 deletions
|
@ -344,12 +344,11 @@ EXPORT_SYMBOL(allocate_resource);
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -EBUSY if the resource can't be inserted.
|
* Returns 0 on success, -EBUSY if the resource can't be inserted.
|
||||||
*
|
*
|
||||||
* This function is equivalent of request_resource when no conflict
|
* This function is equivalent to request_resource when no conflict
|
||||||
* happens. If a conflict happens, and the conflicting resources
|
* happens. If a conflict happens, and the conflicting resources
|
||||||
* entirely fit within the range of the new resource, then the new
|
* entirely fit within the range of the new resource, then the new
|
||||||
* resource is inserted and the conflicting resources become childs of
|
* resource is inserted and the conflicting resources become children of
|
||||||
* the new resource. Otherwise the new resource becomes the child of
|
* the new resource.
|
||||||
* the conflicting resource
|
|
||||||
*/
|
*/
|
||||||
int insert_resource(struct resource *parent, struct resource *new)
|
int insert_resource(struct resource *parent, struct resource *new)
|
||||||
{
|
{
|
||||||
|
@ -357,20 +356,21 @@ int insert_resource(struct resource *parent, struct resource *new)
|
||||||
struct resource *first, *next;
|
struct resource *first, *next;
|
||||||
|
|
||||||
write_lock(&resource_lock);
|
write_lock(&resource_lock);
|
||||||
begin:
|
|
||||||
result = 0;
|
|
||||||
first = __request_resource(parent, new);
|
|
||||||
if (!first)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
result = -EBUSY;
|
for (;; parent = first) {
|
||||||
if (first == parent)
|
result = 0;
|
||||||
goto out;
|
first = __request_resource(parent, new);
|
||||||
|
if (!first)
|
||||||
|
goto out;
|
||||||
|
|
||||||
/* Resource fully contained by the clashing resource? Recurse into it */
|
result = -EBUSY;
|
||||||
if (first->start <= new->start && first->end >= new->end) {
|
if (first == parent)
|
||||||
parent = first;
|
goto out;
|
||||||
goto begin;
|
|
||||||
|
if ((first->start > new->start) || (first->end < new->end))
|
||||||
|
break;
|
||||||
|
if ((first->start == new->start) && (first->end == new->end))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (next = first; ; next = next->sibling) {
|
for (next = first; ; next = next->sibling) {
|
||||||
|
|
Loading…
Reference in a new issue