question about list_for_each_entry_safe

G

gaoqiang

in linux kernel,there is such code that:
213 /**
214 * list_for_each_entry_safe - iterate over list of given type safe
against removal of list entry
215 * @pos: the type * to use as a loop cursor.
216 * @n: another type * to use as temporary storage
217 * @head: the head for your list.
218 * @member: the name of the list_struct within the struct.
219 */
220 #define list_for_each_entry_safe(pos, n, head, member) \
221 for (pos = list_entry((head)->next, typeof(*pos), member), \
222 n = list_entry(pos->member.next, typeof(*pos), member); \
223 &pos->member != (head); \
224 pos = n, n = list_entry(n->member.next, typeof(*n),
member))


why an additional param "n" should passed in?

I think the following code will work fun....

#define list_for_each_entry_safe(pos, head, member) \
--->> typeof(*pos) *_tmp_n_;
 
I

Ike Naar

in linux kernel,there is such code that:
213 /**
214 * list_for_each_entry_safe - iterate over list of given type safe
against removal of list entry
215 * @pos: the type * to use as a loop cursor.
216 * @n: another type * to use as temporary storage
217 * @head: the head for your list.
218 * @member: the name of the list_struct within the struct.
219 */
220 #define list_for_each_entry_safe(pos, n, head, member) \
221 for (pos = list_entry((head)->next, typeof(*pos), member), \
222 n = list_entry(pos->member.next, typeof(*pos), member); \
223 &pos->member != (head); \
224 pos = n, n = list_entry(n->member.next, typeof(*n),
member))


why an additional param "n" should passed in?

I think the following code will work fun....

#define list_for_each_entry_safe(pos, head, member) \
--->> typeof(*pos) *_tmp_n_;

Then the macro would break silently when called with an argument
with that name, e.g.

{
/* declaration of _tmp_n_ */
/* ... */
list_for_each_entry_safe(_tmp_n_, some_head, some_member);
/* ... */
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top