Split single loop going over all pfn in mem_blk into 2 loops,
where outer loop goes over all sections and inner loop goes over
pfn from that section.

This is preparatory patch for next patch:
  "skip non-present sections in register_mem_sect_under_node"

Signed-off-by: Jan Stancek <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
---
 drivers/base/node.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index 31df474d72f4..4c7423a4b5f4 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -379,33 +379,40 @@ static int __init_refok get_nid_for_pfn(unsigned long pfn)
 int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
 {
        int ret;
-       unsigned long pfn, sect_start_pfn, sect_end_pfn;
+       unsigned long pfn, sect_start_pfn, sect_end_pfn, sect_no;
 
        if (!mem_blk)
                return -EFAULT;
        if (!node_online(nid))
                return 0;
 
-       sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
-       sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
-       sect_end_pfn += PAGES_PER_SECTION - 1;
-       for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
-               int page_nid;
+       for (sect_no = mem_blk->start_section_nr;
+               sect_no <= mem_blk->end_section_nr;
+               sect_no++) {
 
-               page_nid = get_nid_for_pfn(pfn);
-               if (page_nid < 0)
-                       continue;
-               if (page_nid != nid)
-                       continue;
-               ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
-                                       &mem_blk->dev.kobj,
-                                       kobject_name(&mem_blk->dev.kobj));
-               if (ret)
-                       return ret;
+               sect_start_pfn = section_nr_to_pfn(sect_no);
+               sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
+
+               for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
+                       int page_nid;
 
-               return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
+                       page_nid = get_nid_for_pfn(pfn);
+                       if (page_nid < 0)
+                               continue;
+                       if (page_nid != nid)
+                               continue;
+
+                       ret = sysfs_create_link_nowarn(
+                               &node_devices[nid]->dev.kobj,
+                               &mem_blk->dev.kobj,
+                               kobject_name(&mem_blk->dev.kobj));
+                       if (ret)
+                               return ret;
+
+                       return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
                                &node_devices[nid]->dev.kobj,
                                kobject_name(&node_devices[nid]->dev.kobj));
+               }
        }
        /* mem section does not span the specified node */
        return 0;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to