Skip to content

Commit 6eada01

Browse files
edumazetdavem330
authored andcommitted
netns: constify net_hash_mix() and various callers
const qualifiers ease code review by making clear which objects are not written in a function. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8f6320d commit 6eada01

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

include/linux/udp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static inline struct udphdr *inner_udp_hdr(const struct sk_buff *skb)
3434

3535
#define UDP_HTABLE_SIZE_MIN (CONFIG_BASE_SMALL ? 128 : 256)
3636

37-
static inline int udp_hashfn(struct net *net, unsigned num, unsigned mask)
37+
static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
3838
{
3939
return (num + net_hash_mix(net)) & mask;
4040
}

include/net/inet_hashtables.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ inet_bind_bucket_create(struct kmem_cache *cachep, struct net *net,
221221
void inet_bind_bucket_destroy(struct kmem_cache *cachep,
222222
struct inet_bind_bucket *tb);
223223

224-
static inline int inet_bhashfn(struct net *net, const __u16 lport,
225-
const int bhash_size)
224+
static inline u32 inet_bhashfn(const struct net *net, const __u16 lport,
225+
const u32 bhash_size)
226226
{
227227
return (lport + net_hash_mix(net)) & (bhash_size - 1);
228228
}
@@ -231,7 +231,7 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
231231
const unsigned short snum);
232232

233233
/* These can have wildcards, don't try too hard. */
234-
static inline int inet_lhashfn(struct net *net, const unsigned short num)
234+
static inline u32 inet_lhashfn(const struct net *net, const unsigned short num)
235235
{
236236
return (num + net_hash_mix(net)) & (INET_LHTABLE_SIZE - 1);
237237
}

include/net/netns/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
struct net;
77

8-
static inline unsigned int net_hash_mix(struct net *net)
8+
static inline u32 net_hash_mix(const struct net *net)
99
{
1010
#ifdef CONFIG_NET_NS
1111
/*
1212
* shift this right to eliminate bits, that are
1313
* always zeroed
1414
*/
1515

16-
return (unsigned)(((unsigned long)net) >> L1_CACHE_SHIFT);
16+
return (u32)(((unsigned long)net) >> L1_CACHE_SHIFT);
1717
#else
1818
return 0;
1919
#endif

net/ipv4/devinet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = {
107107

108108
static struct hlist_head inet_addr_lst[IN4_ADDR_HSIZE];
109109

110-
static u32 inet_addr_hash(struct net *net, __be32 addr)
110+
static u32 inet_addr_hash(const struct net *net, __be32 addr)
111111
{
112112
u32 val = (__force u32) addr ^ net_hash_mix(net);
113113

net/ipv4/inet_hashtables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include <net/secure_seq.h>
2525
#include <net/ip.h>
2626

27-
static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
28-
const __u16 lport, const __be32 faddr,
29-
const __be16 fport)
27+
static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
28+
const __u16 lport, const __be32 faddr,
29+
const __be16 fport)
3030
{
3131
static u32 inet_ehash_secret __read_mostly;
3232

net/ipv4/ping.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ EXPORT_SYMBOL_GPL(pingv6_ops);
6464

6565
static u16 ping_port_rover;
6666

67-
static inline int ping_hashfn(struct net *net, unsigned int num, unsigned int mask)
67+
static inline u32 ping_hashfn(const struct net *net, u32 num, u32 mask)
6868
{
69-
int res = (num + net_hash_mix(net)) & mask;
69+
u32 res = (num + net_hash_mix(net)) & mask;
7070

71-
pr_debug("hash(%d) = %d\n", num, res);
71+
pr_debug("hash(%u) = %u\n", num, res);
7272
return res;
7373
}
7474
EXPORT_SYMBOL_GPL(ping_hash);

net/ipv4/udp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
318318
inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
319319
}
320320

321-
static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
322-
unsigned int port)
321+
static u32 udp4_portaddr_hash(const struct net *net, __be32 saddr,
322+
unsigned int port)
323323
{
324324
return jhash_1word((__force u32)saddr, net_hash_mix(net)) ^ port;
325325
}
@@ -421,9 +421,9 @@ static inline int compute_score2(struct sock *sk, struct net *net,
421421
return score;
422422
}
423423

424-
static unsigned int udp_ehashfn(struct net *net, const __be32 laddr,
425-
const __u16 lport, const __be32 faddr,
426-
const __be16 fport)
424+
static u32 udp_ehashfn(const struct net *net, const __be32 laddr,
425+
const __u16 lport, const __be32 faddr,
426+
const __be16 fport)
427427
{
428428
static u32 udp_ehash_secret __read_mostly;
429429

net/ipv6/inet6_hashtables.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include <net/secure_seq.h>
2424
#include <net/ip.h>
2525

26-
static unsigned int inet6_ehashfn(struct net *net,
27-
const struct in6_addr *laddr,
28-
const u16 lport,
29-
const struct in6_addr *faddr,
30-
const __be16 fport)
26+
static u32 inet6_ehashfn(const struct net *net,
27+
const struct in6_addr *laddr,
28+
const u16 lport,
29+
const struct in6_addr *faddr,
30+
const __be16 fport)
3131
{
3232
static u32 inet6_ehash_secret __read_mostly;
3333
static u32 ipv6_hash_secret __read_mostly;

net/ipv6/udp.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
#include <trace/events/skb.h>
5454
#include "udp_impl.h"
5555

56-
static unsigned int udp6_ehashfn(struct net *net,
57-
const struct in6_addr *laddr,
58-
const u16 lport,
59-
const struct in6_addr *faddr,
60-
const __be16 fport)
56+
static u32 udp6_ehashfn(const struct net *net,
57+
const struct in6_addr *laddr,
58+
const u16 lport,
59+
const struct in6_addr *faddr,
60+
const __be16 fport)
6161
{
6262
static u32 udp6_ehash_secret __read_mostly;
6363
static u32 udp_ipv6_hash_secret __read_mostly;
@@ -104,9 +104,9 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104104
return 0;
105105
}
106106

107-
static unsigned int udp6_portaddr_hash(struct net *net,
108-
const struct in6_addr *addr6,
109-
unsigned int port)
107+
static u32 udp6_portaddr_hash(const struct net *net,
108+
const struct in6_addr *addr6,
109+
unsigned int port)
110110
{
111111
unsigned int hash, mix = net_hash_mix(net);
112112

0 commit comments

Comments
 (0)