From 83ce4c20bb20c9d3b58cf15a9f65ab66872466e9 Mon Sep 17 00:00:00 2001 From: thorpej Date: Sun, 15 Mar 2020 23:14:41 +0000 Subject: [PATCH] Add and use a new function, mowner_init_owner(), that initializes an MBUFTRACE mowner structure (so that providers of it don't have to grovel the internals). --- sys/kern/uipc_mbuf.c | 12 ++++++++++-- sys/net/if_ethersubr.c | 14 ++++---------- sys/sys/mbuf.h | 4 +++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 9cc1e39cccd4..c8e9bcb46582 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.236 2019/12/06 07:27:07 maxv Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.237 2020/03/15 23:14:41 thorpej Exp $ */ /* * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.236 2019/12/06 07:27:07 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.237 2020/03/15 23:14:41 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" @@ -2053,6 +2053,14 @@ nextchain: #endif /* defined(DDB) */ #if defined(MBUFTRACE) +void +mowner_init_owner(struct mowner *mo, const char *name, const char *descr) +{ + memset(mo, 0, sizeof(*mo)); + strlcpy(mo->mo_name, name, sizeof(mo->mo_name)); + strlcpy(mo->mo_descr, descr, sizeof(mo->mo_descr)); +} + void mowner_attach(struct mowner *mo) { diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 6a5722766054..1bb6ddf3da05 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.282 2020/01/29 04:11:35 thorpej Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.283 2020/03/15 23:14:41 thorpej Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.282 2020/01/29 04:11:35 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.283 2020/03/15 23:14:41 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1007,14 +1007,8 @@ ether_ifattach(struct ifnet *ifp, const uint8_t *lla) ifp->if_broadcastaddr = etherbroadcastaddr; bpf_attach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #ifdef MBUFTRACE - strlcpy(ec->ec_tx_mowner.mo_name, ifp->if_xname, - sizeof(ec->ec_tx_mowner.mo_name)); - strlcpy(ec->ec_tx_mowner.mo_descr, "tx", - sizeof(ec->ec_tx_mowner.mo_descr)); - strlcpy(ec->ec_rx_mowner.mo_name, ifp->if_xname, - sizeof(ec->ec_rx_mowner.mo_name)); - strlcpy(ec->ec_rx_mowner.mo_descr, "rx", - sizeof(ec->ec_rx_mowner.mo_descr)); + mowner_init_owner(&ec->ec_tx_mowner, ifp->if_xname, "tx"); + mowner_init_owner(&ec->ec_rx_mowner, ifp->if_xname, "rx"); MOWNER_ATTACH(&ec->ec_tx_mowner); MOWNER_ATTACH(&ec->ec_rx_mowner); ifp->if_mowner = &ec->ec_tx_mowner; diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 4fa6d8fa33e9..f00656ee6bc5 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $NetBSD: mbuf.h,v 1.225 2020/03/05 15:18:55 riastradh Exp $ */ +/* $NetBSD: mbuf.h,v 1.226 2020/03/15 23:14:41 thorpej Exp $ */ /* * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc. @@ -412,6 +412,7 @@ extern const char * const mbuftypes[]; #ifdef MBUFTRACE /* Mbuf allocation tracing. */ +void mowner_init_owner(struct mowner *, const char *, const char *); void mowner_init(struct mbuf *, int); void mowner_ref(struct mbuf *, int); void m_claim(struct mbuf *, struct mowner *); @@ -420,6 +421,7 @@ void mowner_attach(struct mowner *); void mowner_detach(struct mowner *); void m_claimm(struct mbuf *, struct mowner *); #else +#define mowner_init_owner(mo, n, d) __nothing #define mowner_init(m, type) __nothing #define mowner_ref(m, flags) __nothing #define mowner_revoke(m, all, flags) __nothing