From 6a61e3ddef9be9be587a32a406ceb364e246cc15 Mon Sep 17 00:00:00 2001
From: Liam Mark <lmark@codeaurora.org>
Date: Mon, 29 Sep 2014 11:53:04 -0700
Subject: [PATCH] linux-ramdump-parser-v2: support empty lists

Allow empty lists to identified and successfully iterated.

Change-Id: Ifa13e3a8acffa2672163bd4d4ba1cb71a5c189fd
---
 linux-ramdump-parser-v2/linux_list.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/linux-ramdump-parser-v2/linux_list.py b/linux-ramdump-parser-v2/linux_list.py
index 119b351..c1457f5 100644
--- a/linux-ramdump-parser-v2/linux_list.py
+++ b/linux-ramdump-parser-v2/linux_list.py
@@ -32,12 +32,26 @@ class ListWalker(object):
         self.last_node = node_addr
         self.seen_nodes = []
 
+    def is_empty(self):
+        """Return True if the list is empty, False otherwise.
+
+        """
+        next_node_addr = self.last_node + self.ram_dump.field_offset('struct list_head', 'next')
+        next_node = self.ram_dump.read_word(next_node_addr)
+
+        if next_node == self.last_node:
+            return True
+        else:
+            return False
+
     def walk(self, node_addr, func, *args):
         """Walk the linked list starting at `node_addr', calling `func' on
         each node. `func' will be passed the current node and *args,
         if given.
 
         """
+        if self.is_empty() == True:
+            return
 
         while True:
             if node_addr == 0:
@@ -65,6 +79,9 @@ class ListWalker(object):
         if given.
 
         """
+        if self.is_empty() == True:
+            return
+
         node_addr = self.ram_dump.read_word(node_addr + self.ram_dump.field_offset('struct list_head', 'prev'))
         while True:
             if node_addr == 0:
-- 
GitLab