Commit 3629bc27 authored by David Miller's avatar David Miller Committed by Chris Wright

[PATCH] UDP: Fix reversed logic in udp_get_port()

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: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarChris Wright <chrisw@sous-sol.org>
parent 31ce2d6a
...@@ -167,11 +167,14 @@ int udp_get_port(struct sock *sk, unsigned short snum, ...@@ -167,11 +167,14 @@ int udp_get_port(struct sock *sk, unsigned short snum,
goto gotit; goto gotit;
} }
size = 0; size = 0;
sk_for_each(sk2, node, head) sk_for_each(sk2, node, head) {
if (++size < best_size_so_far) { if (++size >= best_size_so_far)
best_size_so_far = size; goto next;
best = result; }
} best_size_so_far = size;
best = result;
next:
;
} }
result = best; result = best;
for(i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++, result += UDP_HTABLE_SIZE) { for(i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++, result += UDP_HTABLE_SIZE) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment