Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21380b81 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller
Browse files

[XFRM]: Eliminate refcounting confusion by creating __xfrm_state_put().



We often just do an atomic_dec(&x->refcnt) on an xfrm_state object
because we know there is more than 1 reference remaining and thus
we can elide the heavier xfrm_state_put() call.

Do this behind an inline function called __xfrm_state_put() so that is
more obvious and also to allow us to more cleanly add refcount
debugging later.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 85259878
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -403,6 +403,11 @@ unsigned xfrm_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto, unsigned short f


extern void __xfrm_state_destroy(struct xfrm_state *);
extern void __xfrm_state_destroy(struct xfrm_state *);


static inline void __xfrm_state_put(struct xfrm_state *x)
{
	atomic_dec(&x->refcnt);
}

static inline void xfrm_state_put(struct xfrm_state *x)
static inline void xfrm_state_put(struct xfrm_state *x)
{
{
	if (atomic_dec_and_test(&x->refcnt))
	if (atomic_dec_and_test(&x->refcnt))
+1 −1
Original line number Original line Diff line number Diff line
@@ -1423,7 +1423,7 @@ static int pfkey_add(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr,


	if (err < 0) {
	if (err < 0) {
		x->km.state = XFRM_STATE_DEAD;
		x->km.state = XFRM_STATE_DEAD;
		xfrm_state_put(x);
		__xfrm_state_put(x);
		goto out;
		goto out;
	}
	}


+4 −4
Original line number Original line Diff line number Diff line
@@ -220,14 +220,14 @@ static int __xfrm_state_delete(struct xfrm_state *x)
		x->km.state = XFRM_STATE_DEAD;
		x->km.state = XFRM_STATE_DEAD;
		spin_lock(&xfrm_state_lock);
		spin_lock(&xfrm_state_lock);
		list_del(&x->bydst);
		list_del(&x->bydst);
		atomic_dec(&x->refcnt);
		__xfrm_state_put(x);
		if (x->id.spi) {
		if (x->id.spi) {
			list_del(&x->byspi);
			list_del(&x->byspi);
			atomic_dec(&x->refcnt);
			__xfrm_state_put(x);
		}
		}
		spin_unlock(&xfrm_state_lock);
		spin_unlock(&xfrm_state_lock);
		if (del_timer(&x->timer))
		if (del_timer(&x->timer))
			atomic_dec(&x->refcnt);
			__xfrm_state_put(x);


		/* The number two in this test is the reference
		/* The number two in this test is the reference
		 * mentioned in the comment below plus the reference
		 * mentioned in the comment below plus the reference
@@ -243,7 +243,7 @@ static int __xfrm_state_delete(struct xfrm_state *x)
		 * The xfrm_state_alloc call gives a reference, and that
		 * The xfrm_state_alloc call gives a reference, and that
		 * is what we are dropping here.
		 * is what we are dropping here.
		 */
		 */
		atomic_dec(&x->refcnt);
		__xfrm_state_put(x);
		err = 0;
		err = 0;
	}
	}


+1 −1
Original line number Original line Diff line number Diff line
@@ -345,7 +345,7 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma)


	if (err < 0) {
	if (err < 0) {
		x->km.state = XFRM_STATE_DEAD;
		x->km.state = XFRM_STATE_DEAD;
		xfrm_state_put(x);
		__xfrm_state_put(x);
		goto out;
		goto out;
	}
	}