RE: list_entry() question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----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.

 
> 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.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux