From 8f99bf68067d2939eb57d2dd46d490579c9686e8 Mon Sep 17 00:00:00 2001 From: visa Date: Thu, 17 Mar 2022 14:22:03 +0000 Subject: [PATCH] Use the refcnt API in bpf. OK sashan@ bluhm@ --- sys/net/bpf.c | 9 +++++---- sys/net/bpfdesc.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index ca6dc2e6744..f882923b376 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.215 2022/02/15 08:43:50 visa Exp $ */ +/* $OpenBSD: bpf.c,v 1.216 2022/03/17 14:22:03 visa Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -398,7 +399,7 @@ bpfopen(dev_t dev, int flag, int mode, struct proc *p) 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); diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h index f7508998487..8e03b3e3c01 100644 --- a/sys/net/bpfdesc.h +++ b/sys/net/bpfdesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bpfdesc.h,v 1.45 2021/01/21 12:33:14 dlg Exp $ */ +/* $OpenBSD: bpfdesc.h,v 1.46 2022/03/17 14:22:03 visa Exp $ */ /* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */ /* @@ -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 */ -- 2.20.1