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>
This commit is contained in:
parent
4da79504b2
commit
49e8ab03eb
|
@ -227,18 +227,16 @@ EXPORT_SYMBOL(inet_ehash_secret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* inet_ehash_secret must be set exactly once
|
* inet_ehash_secret must be set exactly once
|
||||||
* Instead of using a dedicated spinlock, we (ab)use inetsw_lock
|
|
||||||
*/
|
*/
|
||||||
void build_ehash_secret(void)
|
void build_ehash_secret(void)
|
||||||
{
|
{
|
||||||
u32 rnd;
|
u32 rnd;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
get_random_bytes(&rnd, sizeof(rnd));
|
get_random_bytes(&rnd, sizeof(rnd));
|
||||||
} while (rnd == 0);
|
} while (rnd == 0);
|
||||||
spin_lock_bh(&inetsw_lock);
|
|
||||||
if (!inet_ehash_secret)
|
cmpxchg(&inet_ehash_secret, 0, rnd);
|
||||||
inet_ehash_secret = rnd;
|
|
||||||
spin_unlock_bh(&inetsw_lock);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(build_ehash_secret);
|
EXPORT_SYMBOL(build_ehash_secret);
|
||||||
|
|
||||||
|
|
|
@ -1268,18 +1268,11 @@ skip_hashing:
|
||||||
|
|
||||||
void rt_bind_peer(struct rtable *rt, int create)
|
void rt_bind_peer(struct rtable *rt, int create)
|
||||||
{
|
{
|
||||||
static DEFINE_SPINLOCK(rt_peer_lock);
|
|
||||||
struct inet_peer *peer;
|
struct inet_peer *peer;
|
||||||
|
|
||||||
peer = inet_getpeer(rt->rt_dst, create);
|
peer = inet_getpeer(rt->rt_dst, create);
|
||||||
|
|
||||||
spin_lock_bh(&rt_peer_lock);
|
if (peer && cmpxchg(&rt->peer, NULL, peer) != NULL)
|
||||||
if (rt->peer == NULL) {
|
|
||||||
rt->peer = peer;
|
|
||||||
peer = NULL;
|
|
||||||
}
|
|
||||||
spin_unlock_bh(&rt_peer_lock);
|
|
||||||
if (peer)
|
|
||||||
inet_putpeer(peer);
|
inet_putpeer(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue