]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
[PATCH] UDP: Fix reversed logic in udp_get_port()
authorDavid Miller <davem@davemloft.net>
Fri, 22 Dec 2006 19:56:21 +0000 (11:56 -0800)
committerChris Wright <chrisw@sous-sol.org>
Wed, 10 Jan 2007 19:05:20 +0000 (11:05 -0800)
When this code was converted to use sk_for_each() the
logic for the "best hash chain length" code was reversed,
breaking everything.

The original code was of the form:

size = 0;
do {
if (++size >= best_size_so_far)
goto next;
} while ((sk = sk->next) != NULL);
best_size_so_far = size;
best = result;
next:;

and this got converted into:

sk_for_each(sk2, node, head)
if (++size < best_size_so_far) {
best_size_so_far = size;
best = result;
}

Which does something very very different from the original.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
net/ipv4/udp.c

index 9e1bd374875e2f86f96dcb2f768849f20ed67c52..404dd214796381da05a3f58e098e9384825d1bd3 100644 (file)
@@ -167,11 +167,14 @@ int udp_get_port(struct sock *sk, unsigned short snum,
                                goto gotit;
                        }
                        size = 0;
-                       sk_for_each(sk2, node, head)
-                               if (++size < best_size_so_far) {
-                                       best_size_so_far = size;
-                                       best = result;
-                               }
+                       sk_for_each(sk2, node, head) {
+                               if (++size >= best_size_so_far)
+                                       goto next;
+                       }
+                       best_size_so_far = size;
+                       best = result;
+               next:
+                       ;
                }
                result = best;
                for(i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++, result += UDP_HTABLE_SIZE) {