diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-08-19 02:10:45 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-08-20 03:50:16 -0400 |
commit | 49e8ab03ebcacd8e37660ffec20c0c46721a2800 (patch) | |
tree | 78f17093ffdbf4e2cd788033f113888c472f0d7b /net | |
parent | 4da79504b2b41410dd56e9268c9ad403aa65e89c (diff) |
net: build_ehash_secret() and rt_bind_peer() cleanups
Now cmpxchg() is available on all arches, we can use it in
build_ehash_secret() and rt_bind_peer() instead of using spinlocks.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/af_inet.c | 8 | ||||
-rw-r--r-- | net/ipv4/route.c | 9 |
2 files changed, 4 insertions, 13 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 6a1100c25a9f..f581f77d1097 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c | |||
@@ -227,18 +227,16 @@ EXPORT_SYMBOL(inet_ehash_secret); | |||
227 | 227 | ||
228 | /* | 228 | /* |
229 | * inet_ehash_secret must be set exactly once | 229 | * inet_ehash_secret must be set exactly once |
230 | * Instead of using a dedicated spinlock, we (ab)use inetsw_lock | ||
231 | */ | 230 | */ |
232 | void build_ehash_secret(void) | 231 | void build_ehash_secret(void) |
233 | { | 232 | { |
234 | u32 rnd; | 233 | u32 rnd; |
234 | |||
235 | do { | 235 | do { |
236 | get_random_bytes(&rnd, sizeof(rnd)); | 236 | get_random_bytes(&rnd, sizeof(rnd)); |
237 | } while (rnd == 0); | 237 | } while (rnd == 0); |
238 | spin_lock_bh(&inetsw_lock); | 238 | |
239 | if (!inet_ehash_secret) | 239 | cmpxchg(&inet_ehash_secret, 0, rnd); |
240 | inet_ehash_secret = rnd; | ||
241 | spin_unlock_bh(&inetsw_lock); | ||
242 | } | 240 | } |
243 | EXPORT_SYMBOL(build_ehash_secret); | 241 | EXPORT_SYMBOL(build_ehash_secret); |
244 | 242 | ||
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 3f56b6e6c6aa..85a67c9d5982 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -1268,18 +1268,11 @@ skip_hashing: | |||
1268 | 1268 | ||
1269 | void rt_bind_peer(struct rtable *rt, int create) | 1269 | void rt_bind_peer(struct rtable *rt, int create) |
1270 | { | 1270 | { |
1271 | static DEFINE_SPINLOCK(rt_peer_lock); | ||
1272 | struct inet_peer *peer; | 1271 | struct inet_peer *peer; |
1273 | 1272 | ||
1274 | peer = inet_getpeer(rt->rt_dst, create); | 1273 | peer = inet_getpeer(rt->rt_dst, create); |
1275 | 1274 | ||
1276 | spin_lock_bh(&rt_peer_lock); | 1275 | if (peer && cmpxchg(&rt->peer, NULL, peer) != NULL) |
1277 | if (rt->peer == NULL) { | ||
1278 | rt->peer = peer; | ||
1279 | peer = NULL; | ||
1280 | } | ||
1281 | spin_unlock_bh(&rt_peer_lock); | ||
1282 | if (peer) | ||
1283 | inet_putpeer(peer); | 1276 | inet_putpeer(peer); |
1284 | } | 1277 | } |
1285 | 1278 | ||