* [LARTC] LIST_FIND in netfilter_ipv4/listhelp.h
@ 2003-10-06 14:44 jeremie le-hen
2003-10-07 14:25 ` Thomas Graf
0 siblings, 1 reply; 2+ messages in thread
From: jeremie le-hen @ 2003-10-06 14:44 UTC (permalink / raw)
To: lartc
Hi folks,
I'm currently trying to make a patch on conntrack module. While reading some
code I saw the following in include/linux/netfilter_ipv4/listhelp.h :
/* Works on circular linked list. */
#define LIST_FIND(head, cmpfn, type, args...) \
({ \
const struct list_head *__i = (head); \
\
ASSERT_READ_LOCK(head); \
do { \
__i = __i->next; \
if (__i = (head)) { \
__i = NULL; \
break; \
} \
} while (!cmpfn((const type)__i , ## args)); \
(type)__i; \
})
Unless I really drank too much yesterday evening, I'm pretty sure this
algorithm will fail if the list has only one element, returning NULL
immediately without even trying to compare the element.
On the other hand, it seems to work pretty well for months, since it is
widely used accross the NetFilter conntrack code. So where am I wrong ?
Thanks in advance.
Regards,
--
Jeremie LE HEN aka TtZ/TataZ jeremie.le-hen@epita.fr
ttz@epita.fr
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [LARTC] LIST_FIND in netfilter_ipv4/listhelp.h
2003-10-06 14:44 [LARTC] LIST_FIND in netfilter_ipv4/listhelp.h jeremie le-hen
@ 2003-10-07 14:25 ` Thomas Graf
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Graf @ 2003-10-07 14:25 UTC (permalink / raw)
To: lartc
Hi
* jeremie le-hen <20031006144458.GD24864@carpediem.epita.fr> 2003-10-06 16:44
> Unless I really drank too much yesterday evening, I'm pretty sure this
> algorithm will fail if the list has only one element, returning NULL
> immediately without even trying to compare the element.
> On the other hand, it seems to work pretty well for months, since it is
> widely used accross the NetFilter conntrack code. So where am I wrong ?
The code is correct.
Check include/linux/list.h, it's a cyclic list:
head->next points to first element
head->prev points to last element
the list iteration code will make it clear:
#define __list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
Regards
--
Thomas GRAF <tgraf@suug.ch>
_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-10-07 14:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-06 14:44 [LARTC] LIST_FIND in netfilter_ipv4/listhelp.h jeremie le-hen
2003-10-07 14:25 ` Thomas Graf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.