About head of kernel linked list structure

Mulyadi Santosa mulyadi.santosa at gmail.com
Thu May 7 06:57:19 EDT 2015


On Wed, May 6, 2015 at 5:39 PM, Huaicheng Li <lhcwhu at gmail.com> wrote:

> In my understanding, the head initialised using LIST_HEAD_INIT or defined
> by LIST_HEAD corresponds to no *real* data field.
> But it *does* have its own _next_ and _prev_ pointers. The _next_ pointer
> points to the first real node in the doubly linked list,
> and the _prev_ pointer points to the last real node.
>
> I'm wondering if the picture shown at the very bottom of *http://kernelnewbies.org/FAQ/LinkedLists
> <http://kernelnewbies.org/FAQ/LinkedLists>* is wrong about this. Because
> I believe head's _prev_ should point to the last node, which is at the
> very right. And the last node's _next_ should point to the head.
> Just as shown like the red line.
>
> Am I right?
>
>
>
>

Hi Huachieng

AFAIK, if the linked list is not circular one, the last node's next should
point to NULL, so does the head prev's. This is done so you know when you
hit head i.e

if !(head.prev)
{
      // we're at head
}



-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150507/a7d3605c/attachment-0001.html 


More information about the Kernelnewbies mailing list