LIST_FIND in netfilter_ipv4/listhelp.h

Linux Advanced Routing and Traffic Control

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

 



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@xxxxxxxx
                                                                 ttz@xxxxxxxx
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
_______________________________________________
LARTC mailing list / LARTC@xxxxxxxxxxxxxxx
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux