From: lhcwhu@gmail.com (Huaicheng Li) Date: Thu, 7 May 2015 18:52:22 +0800 Subject: About head of kernel linked list structure In-Reply-To: References: <266D09DB-B80D-4DAC-85D9-DFB444A1015D@gmail.com> Message-ID: <1D347A71-9393-49DD-9EDE-464D5AB265EA@gmail.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi Robert, You got my point and I?m sorry for not stating it in a clear way. You are right about the "prev-to-left" and "next-to-right" when drawing the line. At that time, I just wanted to show which node they were pointing at. Anyway, you solved my puzzle. Also thanks for your excellent article. -- Best Regards Huaicheng Li > On May 7, 2015, at 3:45 AM, Robert P. J. Day wrote: > > On Wed, 6 May 2015, Huaicheng Li wrote: > >> In my understanding, the head initialised using LIST_HEAD_INIT or >> defined by LIST_HEAD corresponds to no *real* data field. > > correct. a better way to describe it would be that it corresponds to > no real enclosing payload, so it should never be dereferenced to get > to said payload. > >> 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. > > so far, so good -- by "real", you mean list heads that actually > correspond to an enclosing payload. > >> I'm wondering if the picture shown at the very bottom of >> 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? > > it looks fine to me, although my standard is to show next pointers > going to the right, and prev to the left, but this way looks fine. > maybe i'm misunderstanding your objection. > > i once wrote a tutorial on LLs: > > http://www.crashcourse.ca/introduction-linux-kernel-programming/intermission-lets-talk-about-linked-lists-and-containerof-free > > rday > > -- > > ======================================================================== > Robert P. J. Day Ottawa, Ontario, CANADA > http://crashcourse.ca > > Twitter: http://twitter.com/rpjday > LinkedIn: http://ca.linkedin.com/in/rpjday > ========================================================================