netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / kernel / resource.c
index 78b0872..af96c1e 100644 (file)
@@ -223,13 +223,13 @@ int release_resource(struct resource *old)
 
 EXPORT_SYMBOL(release_resource);
 
-#if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
+#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
 /*
  * Finds the lowest memory reosurce exists within [res->start.res->end)
- * the caller must specify res->start, res->end, res->flags.
+ * the caller must specify res->start, res->end, res->flags and "name".
  * If found, returns 0, res is overwritten, if not found, returns -1.
  */
-static int find_next_system_ram(struct resource *res)
+static int find_next_system_ram(struct resource *res, char *name)
 {
        resource_size_t start, end;
        struct resource *p;
@@ -245,6 +245,8 @@ static int find_next_system_ram(struct resource *res)
                /* system ram is just marked as IORESOURCE_MEM */
                if (p->flags != res->flags)
                        continue;
+               if (name && strcmp(p->name, name))
+                       continue;
                if (p->start > end) {
                        p = NULL;
                        break;
@@ -262,19 +264,26 @@ static int find_next_system_ram(struct resource *res)
                res->end = p->end;
        return 0;
 }
-int
-walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg,
-                       int (*func)(unsigned long, unsigned long, void *))
+
+/*
+ * This function calls callback against all memory range of "System RAM"
+ * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
+ * Now, this function is only for "System RAM".
+ */
+int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
+               void *arg, int (*func)(unsigned long, unsigned long, void *))
 {
        struct resource res;
        unsigned long pfn, len;
        u64 orig_end;
        int ret = -1;
+
        res.start = (u64) start_pfn << PAGE_SHIFT;
        res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
        res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
        orig_end = res.end;
-       while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
+       while ((res.start < res.end) &&
+               (find_next_system_ram(&res, "System RAM") >= 0)) {
                pfn = (unsigned long)(res.start >> PAGE_SHIFT);
                len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT);
                ret = (*func)(pfn, len, arg);
@@ -299,35 +308,37 @@ static int find_resource(struct resource *root, struct resource *new,
                         void *alignf_data)
 {
        struct resource *this = root->child;
+       struct resource tmp = *new;
 
-       new->start = root->start;
+       tmp.start = root->start;
        /*
         * Skip past an allocated resource that starts at 0, since the assignment
-        * of this->start - 1 to new->end below would cause an underflow.
+        * of this->start - 1 to tmp->end below would cause an underflow.
         */
        if (this && this->start == 0) {
-               new->start = this->end + 1;
+               tmp.start = this->end + 1;
                this = this->sibling;
        }
        for(;;) {
                if (this)
-                       new->end = this->start - 1;
+                       tmp.end = this->start - 1;
                else
-                       new->end = root->end;
-               if (new->start < min)
-                       new->start = min;
-               if (new->end > max)
-                       new->end = max;
-               new->start = ALIGN(new->start, align);
+                       tmp.end = root->end;
+               if (tmp.start < min)
+                       tmp.start = min;
+               if (tmp.end > max)
+                       tmp.end = max;
+               tmp.start = ALIGN(tmp.start, align);
                if (alignf)
-                       alignf(alignf_data, new, size, align);
-               if (new->start < new->end && new->end - new->start >= size - 1) {
-                       new->end = new->start + size - 1;
+                       alignf(alignf_data, &tmp, size, align);
+               if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) {
+                       new->start = tmp.start;
+                       new->end = tmp.start + size - 1;
                        return 0;
                }
                if (!this)
                        break;
-               new->start = this->end + 1;
+               tmp.start = this->end + 1;
                this = this->sibling;
        }
        return -EBUSY;