The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1b7d0c2ee94748814a6c7943806ab8160e65a6f5
commit 1b7d0c2ee94748814a6c7943806ab8160e65a6f5 Author: Konstantin Belousov <k...@freebsd.org> AuthorDate: 2025-07-03 10:36:58 +0000 Commit: Konstantin Belousov <k...@freebsd.org> CommitDate: 2025-07-10 14:42:27 +0000 in_pcb: add in_pcbrele_rlock() The helper that derefs and rlocks the provided inp. Returns false if inp is still usable. Reviewed by: glebius, markj Sponsored by: Nvidia networking Differential revision: https://reviews.freebsd.org/D51143 --- sys/netinet/in_pcb.c | 17 +++++++++++++++++ sys/netinet/in_pcb.h | 1 + 2 files changed, 18 insertions(+) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index bccd4b84561a..dbe48242381d 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1744,6 +1744,23 @@ in_pcbrele(struct inpcb *inp, const inp_lookup_t lock) in_pcbrele_rlocked(inp) : in_pcbrele_wlocked(inp)); } +/* + * Dereference and rlock inp, for which the caller must own the + * reference. Returns true if inp no longer usable, false otherwise. + */ +bool +in_pcbrele_rlock(struct inpcb *inp) +{ + INP_RLOCK(inp); + if (in_pcbrele_rlocked(inp)) + return (true); + if ((inp->inp_flags & INP_FREED) != 0) { + INP_RUNLOCK(inp); + return (true); + } + return (false); +} + /* * Unconditionally schedule an inpcb to be freed by decrementing its * reference count, which should occur only after the inpcb has been detached diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 57cf15ca37fc..9e0618e87601 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -681,6 +681,7 @@ void in_pcbref(struct inpcb *); bool in_pcbrele(struct inpcb *, inp_lookup_t); bool in_pcbrele_rlocked(struct inpcb *); bool in_pcbrele_wlocked(struct inpcb *); +bool in_pcbrele_rlock(struct inpcb *inp); typedef bool inp_match_t(const struct inpcb *, void *); struct inpcb_iterator {