Skip to content

Commit a49dd9d

Browse files
Asias Hedavem330
authored andcommitted
VSOCK: Fix VSOCK_HASH and VSOCK_CONN_HASH
If we mod with VSOCK_HASH_SIZE -1, we get 0, 1, .... 249. Actually, we have vsock_bind_table[0 ... 250] and vsock_connected_table[0 .. 250]. In this case the last entry will never be used. We should mod with VSOCK_HASH_SIZE instead. Signed-off-by: Asias He <[email protected]> Acked-by: Andy King <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0fc9324 commit a49dd9d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,18 @@ EXPORT_SYMBOL_GPL(vm_sockets_get_local_cid);
144144
* VSOCK_HASH_SIZE + 1 so that vsock_bind_table[0] through
145145
* vsock_bind_table[VSOCK_HASH_SIZE - 1] are for bound sockets and
146146
* vsock_bind_table[VSOCK_HASH_SIZE] is for unbound sockets. The hash function
147-
* mods with VSOCK_HASH_SIZE - 1 to ensure this.
147+
* mods with VSOCK_HASH_SIZE to ensure this.
148148
*/
149149
#define VSOCK_HASH_SIZE 251
150150
#define MAX_PORT_RETRIES 24
151151

152-
#define VSOCK_HASH(addr) ((addr)->svm_port % (VSOCK_HASH_SIZE - 1))
152+
#define VSOCK_HASH(addr) ((addr)->svm_port % VSOCK_HASH_SIZE)
153153
#define vsock_bound_sockets(addr) (&vsock_bind_table[VSOCK_HASH(addr)])
154154
#define vsock_unbound_sockets (&vsock_bind_table[VSOCK_HASH_SIZE])
155155

156156
/* XXX This can probably be implemented in a better way. */
157157
#define VSOCK_CONN_HASH(src, dst) \
158-
(((src)->svm_cid ^ (dst)->svm_port) % (VSOCK_HASH_SIZE - 1))
158+
(((src)->svm_cid ^ (dst)->svm_port) % VSOCK_HASH_SIZE)
159159
#define vsock_connected_sockets(src, dst) \
160160
(&vsock_connected_table[VSOCK_CONN_HASH(src, dst)])
161161
#define vsock_connected_sockets_vsk(vsk) \

0 commit comments

Comments
 (0)