The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d09388d013300fc4aa1ee1a6bc24260cd400aff3

commit d09388d013300fc4aa1ee1a6bc24260cd400aff3
Author:     Mateusz Guzik <[email protected]>
AuthorDate: 2021-06-28 12:18:43 +0000
Commit:     Mateusz Guzik <[email protected]>
CommitDate: 2021-06-28 15:49:20 +0000

    pf: add pf_release_staten and use it in pf_unlink_state
    
    Saves one atomic op.
    
    Reviewed by:    kp
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/net/pfvar.h     | 11 +++++++++++
 sys/netpfil/pf/pf.c |  7 ++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index e07016f7b66c..9578ec0a701f 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1510,6 +1510,17 @@ pf_release_state(struct pf_state *s)
                return (0);
 }
 
+static __inline int
+pf_release_staten(struct pf_state *s, u_int n)
+{
+
+       if (refcount_releasen(&s->refs, n)) {
+               pf_free_state(s);
+               return (1);
+       } else
+               return (0);
+}
+
 extern struct pf_state         *pf_find_state_byid(uint64_t, uint32_t);
 extern struct pf_state         *pf_find_state_all(struct pf_state_key_cmp *,
                                    u_int, int *);
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 7e187a358783..02d0809f738d 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -1732,11 +1732,8 @@ pf_unlink_state(struct pf_state *s, u_int flags)
        PF_HASHROW_UNLOCK(ih);
 
        pf_detach_state(s);
-       /* pf_state_insert() initialises refs to 2, so we can never release the
-        * last reference here, only in pf_release_state(). */
-       (void)refcount_release(&s->refs);
-
-       return (pf_release_state(s));
+       /* pf_state_insert() initialises refs to 2 */
+       return (pf_release_staten(s, 2));
 }
 
 void
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to