Commit 3c5a76a1 authored by Linus Torvalds's avatar Linus Torvalds

Fix "insert_resource()" nesting bug

It used to create totally impossible resource trees in some
circumstances where it was asked to insert a conflicting
resource. We never noticed, because it wasn't used that much.

Make it return the proper error instead.
parent 962eb7be
......@@ -315,11 +315,12 @@ EXPORT_SYMBOL(allocate_resource);
*/
int insert_resource(struct resource *parent, struct resource *new)
{
int result = 0;
int result;
struct resource *first, *next;
write_lock(&resource_lock);
begin:
result = 0;
first = __request_resource(parent, new);
if (!first)
goto out;
......@@ -328,15 +329,20 @@ int insert_resource(struct resource *parent, struct resource *new)
if (first == parent)
goto out;
for (next = first; next->sibling; next = next->sibling)
/* Resource fully contained by the clashing resource? Recurse into it */
if (first->start <= new->start && first->end >= new->end) {
parent = first;
goto begin;
}
for (next = first; ; next = next->sibling) {
/* Partial overlap? Bad, and unfixable */
if (next->start < new->start || next->end > new->end)
goto out;
if (!next->sibling)
break;
if (next->sibling->start > new->end)
break;
/* existing resource includes new resource */
if (next->end >= new->end) {
parent = next;
result = 0;
goto begin;
}
result = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment