Index: kernel/generic/include/adt/list.h
===================================================================
--- kernel/generic/include/adt/list.h	(revision ba2be23ed5b64c117eabda6070c8ad4ea3c56df6)
+++ kernel/generic/include/adt/list.h	(revision 47b27b40836439054f5594614fa35fbd70a2c0bf)
@@ -67,7 +67,9 @@
 	((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
 
-#define list_foreach(list, iterator) \
-	for (link_t *iterator = (list).head.next; \
-	    iterator != &(list).head; iterator = iterator->next)
+#define list_foreach(list, member, itype, iterator) \
+	for (itype *iterator = NULL; iterator == NULL; iterator =(itype *)1) \
+	    for (link_t *_link = (list).head.next; \
+	    iterator = list_get_instance(_link, itype, member), \
+	    _link != &(list).head; _link = _link->next)
 
 #define assert_link_not_used(link) \
@@ -184,5 +186,4 @@
  * @return Head item of the list.
  * @return NULL if the list is empty.
- *
  */
 static inline link_t *list_first(const list_t *list)
@@ -197,9 +198,32 @@
  * @return Head item of the list.
  * @return NULL if the list is empty.
- *
  */
 static inline link_t *list_last(list_t *list)
 {
 	return ((list->head.prev == &list->head) ? NULL : list->head.prev);
+}
+
+/** Get next item in list.
+ *
+ * @param link Current item link
+ * @param list List containing @a link
+ *
+ * @return Next item or NULL if @a link is the last item.
+ */
+static inline link_t *list_next(link_t *link, const list_t *list)
+{
+	return (link->next == &list->head) ? NULL : link->next;
+}
+
+/** Get previous item in list.
+ *
+ * @param link Current item link
+ * @param list List containing @a link
+ *
+ * @return Previous item or NULL if @a link is the first item.
+ */
+static inline link_t *list_prev(link_t *link, const list_t *list)
+{
+	return (link->prev == &list->head) ? NULL : link->prev;
 }
 
@@ -270,10 +294,13 @@
 {
 	unsigned int cnt = 0;
-	
-	list_foreach(*list, link) {
+	link_t *link;
+	
+	link = list_first(list);
+	while (link != NULL) {
 		if (cnt == n)
 			return link;
 		
 		cnt++;
+		link = list_next(link, list);
 	}
 	
