resources: allow adjust_resource() for resources with no parent
authorYinghai Lu <yinghai@kernel.org>
Fri, 18 May 2012 01:51:11 +0000 (18:51 -0700)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 13 Jun 2012 21:42:22 +0000 (15:42 -0600)
If a resource has no parent, allow its start/end to be set arbitrarily
as long as any children are still contained within the new range.

[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
kernel/resource.c

index e1d2b8ee76d5bcd22d552c21cdf2102eaf6c7627..dc8b477644436730bea0165a1ca6fd7f179b3144 100644 (file)
@@ -722,14 +722,12 @@ int adjust_resource(struct resource *res, resource_size_t start, resource_size_t
 
        write_lock(&resource_lock);
 
+       if (!parent)
+               goto skip;
+
        if ((start < parent->start) || (end > parent->end))
                goto out;
 
-       for (tmp = res->child; tmp; tmp = tmp->sibling) {
-               if ((tmp->start < start) || (tmp->end > end))
-                       goto out;
-       }
-
        if (res->sibling && (res->sibling->start <= end))
                goto out;
 
@@ -741,6 +739,11 @@ int adjust_resource(struct resource *res, resource_size_t start, resource_size_t
                        goto out;
        }
 
+skip:
+       for (tmp = res->child; tmp; tmp = tmp->sibling)
+               if ((tmp->start < start) || (tmp->end > end))
+                       goto out;
+
        res->start = start;
        res->end = end;
        result = 0;