Use the refcnt API in bpf.
OK?
Index: net/bpf.c
===================================================================
RCS file: src/sys/net/bpf.c,v
retrieving revision 1.215
diff -u -p -r1.215 bpf.c
--- net/bpf.c 15 Feb 2022 08:43:50 -0000 1.215
+++ net/bpf.c 16 Mar 2022 15:42:05 -0000
@@ -55,6 +55,7 @@
#include <sys/sysctl.h>
#include <sys/rwlock.h>
#include <sys/atomic.h>
+#include <sys/refcnt.h>
#include <sys/smr.h>
#include <sys/specdev.h>
#include <sys/selinfo.h>
@@ -398,7 +399,7 @@ bpfopen(dev_t dev, int flag, int mode, s
bd->bd_rtout = 0; /* no timeout by default */
- bpf_get(bd);
+ refcnt_init(&bd->bd_refcnt);
LIST_INSERT_HEAD(&bpf_d_list, bd, bd_list);
return (0);
@@ -1645,7 +1646,7 @@ bpf_d_smr(void *smr)
void
bpf_get(struct bpf_d *bd)
{
- atomic_inc_int(&bd->bd_ref);
+ refcnt_take(&bd->bd_refcnt);
}
/*
@@ -1655,7 +1656,7 @@ bpf_get(struct bpf_d *bd)
void
bpf_put(struct bpf_d *bd)
{
- if (atomic_dec_int_nv(&bd->bd_ref) > 0)
+ if (refcnt_rele(&bd->bd_refcnt) == 0)
return;
smr_call(&bd->bd_smr, bpf_d_smr, bd);
Index: net/bpfdesc.h
===================================================================
RCS file: src/sys/net/bpfdesc.h,v
retrieving revision 1.45
diff -u -p -r1.45 bpfdesc.h
--- net/bpfdesc.h 21 Jan 2021 12:33:14 -0000 1.45
+++ net/bpfdesc.h 16 Mar 2022 15:42:05 -0000
@@ -98,7 +98,7 @@ struct bpf_d {
int bd_sig; /* signal to send upon packet reception
*/
struct sigio_ref
bd_sigio; /* async I/O registration */
- u_int bd_ref; /* reference count */
+ struct refcnt bd_refcnt; /* reference count */
struct selinfo bd_sel; /* bsd select info */
int bd_unit; /* logical unit number */
LIST_ENTRY(bpf_d) bd_list; /* descriptor list */