On Mon, 19 Feb 2007, Curran, Dominic wrote: > > -----Original Message----- > > From: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies- > > bounce@xxxxxxxxxxxx] On Behalf Of Srdjan Todorovic > > Sent: Monday, February 19, 2007 2:06 PM > > To: kernelnewbies@xxxxxxxxxxxx > > Subject: list_entry() question > > > > Hello everyone. > > > > I'm converting some scsi driver to use the kernel list API, and have a > > question regarding the list handling. > > > > The driver has several structs that represent the controllers, and > > each controller has a list of work items. Suppose for example: > > > > struct host_controller { > > int foo; > > struct list_head the_list; > > }; > > > > The_list.next will _point_ to the head of the work item list. > > > > struct work_item { > > int blah; > > void *zot; > > struct list_head list_item; > > }; > > > > Suppose I have 2 struct host_controllers, and 10 struct work_item per > > controller. > > > > I walk the list of work items for a controller, using list_for_each() > > and then I get the struct work_item variable using > > list_entry(cursor, struct work_item, list_item); > > > > Now, from what I understand, the head of the list, the struct > > host_controller variable, is in the list because its the_list is > linked > > with the rest of the struct list_head variables that make up the list. > > > > What happens when list_for_each() hits struct host_controller's > the_list > > variable? > > The list_for_each() will stop when it gets to the_list.prev, so this > wont happen. > > I kinda see what youre saying, and I'm probably not explain this well > but what your asking is not going to happen. > Every item you walk with list_for_each() will be of struct type > work_item. I see what you mean. Indeed, every time I do list_for_each(), I'm starting with the struct list_head in the host controller struct, so list_entry() will never see that struct. However, if I started list_for_each() from one of struct work_items, then that might be problematic. Luckily I don't do that so I now don't think it would ever be a problem for what I'm doing. > > What happens when list_entry() tries to get me a struct work_item when > in > > reality the current struct list_head variable is in struct > > host_controller? > > It wont happen. > > LDD explains this well I think. > http://lwn.net/Kernel/LDD3/ > see chapter 11. I had a look at that before, but I didn't think it answered my question. My eyes must have skimmed the for loop version of iterating through the list on page 11. :-) Thanks, Srdjan -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ