Skip to content
Snippets Groups Projects
Commit 775b9548 authored by Adrian Salido-Moreno's avatar Adrian Salido-Moreno
Browse files

lrdp-v2: make ListWalker as iterator

Allow easily iterating through the list by implementing ListWalker
iterator functions.

Change-Id: Idba8cbcb8e3399e6e33f99b993554aeef7420a53
parent 10b3e7aa
No related branches found
No related tags found
No related merge requests found
# Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. # Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 and # it under the terms of the GNU General Public License version 2 and
...@@ -31,11 +31,35 @@ class ListWalker(object): ...@@ -31,11 +31,35 @@ class ListWalker(object):
self.list_elem_offset = list_elem_offset self.list_elem_offset = list_elem_offset
self.last_node = node_addr self.last_node = node_addr
self.seen_nodes = [] self.seen_nodes = []
self.curr_node = node_addr
def __iter__(self):
return self
def next(self):
next_node_addr = self.curr_node + \
self.ram_dump.field_offset('struct list_head', 'next')
next_node = self.ram_dump.read_word(next_node_addr)
self.curr_node = next_node
if next_node == self.last_node:
raise StopIteration()
elif next_node in self.seen_nodes:
print_out_str(
'[!] WARNING: Cycle found in attach list. List is corrupted!')
raise StopIteration()
else:
self.seen_nodes.append(next_node)
return next_node - self.list_elem_offset
def is_empty(self): def is_empty(self):
"""Return True if the list is empty, False otherwise. """Return True if the list is empty, False otherwise.
""" """
if self.last_node is None:
return True
next_node_addr = self.last_node + self.ram_dump.field_offset('struct list_head', 'next') 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) next_node = self.ram_dump.read_word(next_node_addr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment