<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org]
<b>On Behalf Of </b>Mulyadi Santosa<br>
<b>Sent:</b> Thursday, May 07, 2015 3:53 AM<br>
<b>To:</b> Huaicheng Li<br>
<b>Cc:</b> kernelnewbies<br>
<b>Subject:</b> Re: About head of kernel linked list structure<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">On Wed, May 6, 2015 at 5:39 PM, Huaicheng Li &lt;<a href="mailto:lhcwhu@gmail.com" target="_blank">lhcwhu@gmail.com</a>&gt; wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal">In my understanding, the head initialised using LIST_HEAD_INIT or defined by LIST_HEAD corresponds to no *real* data field.&nbsp;<br>
But it *does* have its own _next_ and _prev_ pointers. The _next_ pointer points to the first real node in the doubly linked list,<br>
and the _prev_ pointer points to the last real node.&nbsp;<br>
<br>
I'm wondering if the picture shown at the very bottom of&nbsp;<u><a href="http://kernelnewbies.org/FAQ/LinkedLists" target="_blank">http://kernelnewbies.org/FAQ/LinkedLists</a></u>&nbsp;is wrong about this.&nbsp;Because<br>
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&nbsp;head.<br>
Just as shown like the red line.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
Am I right?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><img border="0" width="132" height="102" id="_x0000_i1025" src="cid:image002.png@01D089A8.8896F550"><o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi Huachieng<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">if !(head.prev)<br>
{<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // we're at head<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<span style="color:#1F497D">Just pointing out that these lists are circular. Back in the old days we used to call them &#8220;rings&#8221;.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">From list.h:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">183 /**<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">184&nbsp; * list_empty - tests whether a list is empty<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">185&nbsp; * @head: the list to test.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">186&nbsp; */<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">187 static inline int list_empty(const struct list_head *head)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">188 {<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:5.25pt"><span style="color:#1F497D">189&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return head-&gt;next == head;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">&nbsp; 190 }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Jeff Haran</span>&nbsp;<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>