[PATCH] Avoid recursion in lockdep when stack tracer takes locks
[powerpc.git] / kernel / resource.c
index cc73029..4628643 100644 (file)
@@ -7,7 +7,6 @@
  * Arbitrary resource management.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
@@ -230,6 +229,47 @@ int release_resource(struct resource *old)
 
 EXPORT_SYMBOL(release_resource);
 
+#ifdef CONFIG_MEMORY_HOTPLUG
+/*
+ * Finds the lowest memory reosurce exists within [res->start.res->end)
+ * the caller must specify res->start, res->end, res->flags.
+ * If found, returns 0, res is overwritten, if not found, returns -1.
+ */
+int find_next_system_ram(struct resource *res)
+{
+       resource_size_t start, end;
+       struct resource *p;
+
+       BUG_ON(!res);
+
+       start = res->start;
+       end = res->end;
+       BUG_ON(start >= end);
+
+       read_lock(&resource_lock);
+       for (p = iomem_resource.child; p ; p = p->sibling) {
+               /* system ram is just marked as IORESOURCE_MEM */
+               if (p->flags != res->flags)
+                       continue;
+               if (p->start > end) {
+                       p = NULL;
+                       break;
+               }
+               if ((p->end >= start) && (p->start < end))
+                       break;
+       }
+       read_unlock(&resource_lock);
+       if (!p)
+               return -1;
+       /* copy data */
+       if (res->start < p->start)
+               res->start = p->start;
+       if (res->end > p->end)
+               res->end = p->end;
+       return 0;
+}
+#endif
+
 /*
  * Find empty slot in the resource tree given range and alignment.
  */
@@ -367,8 +407,6 @@ int insert_resource(struct resource *parent, struct resource *new)
        return result;
 }
 
-EXPORT_SYMBOL(insert_resource);
-
 /*
  * Given an existing resource, change its start and size to match the
  * arguments.  Returns -EBUSY if it can't fit.  Existing children of