I was using list_for_each_entry(datastructureptr , &mylinkedlist, head) to traverse a linked list i created. The output I got was last inserted item is printed first. Is it the expected output. Is there any macro/function to print it in the other way?
2 Answers
list_for_each_entry traverses a list from the first to the last item.
You must ensure that the items are inserted in the correct order and at the correct position.
list_add inserts at the start of the list; list_add_tail at the end.
1 Comment
user567879
I gave the second argument of
list_add as the list head so got the output like that. Thanks for the info.struct private {
char data[30];
struct list_head head;
};
.......
.....
static struct private mylinkedlist;
....
struct private *datastructureptr=&mylinkedlist;
...
list_for_each_entry(datastructureptr , &mylinkedlist, head)
printk( " %s->\n",datastructureptr->data);
prints items in fifo way