list_entry() question

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

 



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;
};

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?

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?

Is this legal?

Many 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


[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