Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Don't use macros, rather inline, much clearer.
details: https://anonhg.NetBSD.org/src/rev/bb057ebee96d
branches: trunk
changeset: 358484:bb057ebee96d
user: maxv <maxv%NetBSD.org@localhost>
date: Mon Jan 01 12:09:56 2018 +0000
description:
Don't use macros, rather inline, much clearer.
For the record, I was partly mistaken in my previous commit: even though
the macros were local, the function names were still the ones of the real
callers.
However, setting the name in m_data was not a good thing; this was a
valid pointer, and the kernel could execute a long time before figuring
out the mbuf was already freed - therefore making debugging more difficult.
And information on the caller can be obtained via ddb anyway.
diffstat:
sys/kern/uipc_mbuf.c | 78 ++++++++++++++++++----------------------------------
sys/sys/mbuf.h | 9 +-----
2 files changed, 28 insertions(+), 59 deletions(-)
diffs (135 lines):
diff -r 1b58ac473927 -r bb057ebee96d sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Mon Jan 01 11:52:45 2018 +0000
+++ b/sys/kern/uipc_mbuf.c Mon Jan 01 12:09:56 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.174 2017/12/31 06:57:12 maxv Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.175 2018/01/01 12:09:56 maxv Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.174 2017/12/31 06:57:12 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.175 2018/01/01 12:09:56 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@@ -1916,66 +1916,42 @@
#endif /* defined(MBUFTRACE) */
/*
- * MFREE(struct mbuf *m, struct mbuf *n)
- * Free a single mbuf and associated external storage.
- * Place the successor, if any, in n.
+ * Free a single mbuf and associated external storage. Return the
+ * successor, if any.
*/
-#define MFREE(f, l, m, n) \
- mowner_revoke((m), 1, (m)->m_flags); \
- mbstat_type_add((m)->m_type, -1); \
- if ((m)->m_flags & M_PKTHDR) \
- m_tag_delete_chain((m), NULL); \
- (n) = (m)->m_next; \
- if ((m)->m_flags & M_EXT) { \
- m_ext_free((m)); \
- } else { \
- MBUFFREE(f, l, m); \
- } \
-
-#define MBUFFREE(f, l, m) \
- do { \
- if (__predict_false((m)->m_type == MT_FREE)) { \
- panic("mbuf %p already freed", m); \
- } \
- (m)->m_type = MT_FREE; \
- (m)->m_data = NULL; \
- pool_cache_put(mb_cache, (m)); \
- } while (/*CONSTCOND*/0)
-
struct mbuf *
-m__free(const char *f, int l, struct mbuf *m)
+m_free(struct mbuf *m)
{
struct mbuf *n;
- MFREE(f, l, m, n);
- return (n);
+ mowner_revoke(m, 1, m->m_flags);
+ mbstat_type_add(m->m_type, -1);
+
+ if (m->m_flags & M_PKTHDR)
+ m_tag_delete_chain(m, NULL);
+
+ n = m->m_next;
+
+ if (m->m_flags & M_EXT) {
+ m_ext_free(m);
+ } else {
+ if (__predict_false(m->m_type == MT_FREE)) {
+ panic("mbuf %p already freed", m);
+ }
+ m->m_type = MT_FREE;
+ m->m_data = NULL;
+ pool_cache_put(mb_cache, m);
+ }
+
+ return n;
}
void
-m__freem(const char *f, int l, struct mbuf *m)
+m_freem(struct mbuf *m)
{
- struct mbuf *n;
-
if (m == NULL)
return;
do {
- MFREE(f, l, m, n);
- m = n;
+ m = m_free(m);
} while (m);
}
-
-#undef m_free
-struct mbuf *m_free(struct mbuf *);
-struct mbuf *
-m_free(struct mbuf *m)
-{
- return m__free(__func__, __LINE__, m);
-}
-
-#undef m_freem
-void m_freem(struct mbuf *);
-void
-m_freem(struct mbuf *m)
-{
- m__freem(__func__, __LINE__, m);
-}
diff -r 1b58ac473927 -r bb057ebee96d sys/sys/mbuf.h
--- a/sys/sys/mbuf.h Mon Jan 01 11:52:45 2018 +0000
+++ b/sys/sys/mbuf.h Mon Jan 01 12:09:56 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.172 2017/11/09 22:34:07 riastradh Exp $ */
+/* $NetBSD: mbuf.h,v 1.173 2018/01/01 12:09:56 maxv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -858,15 +858,8 @@
int m_makewritable(struct mbuf **, int, int, int);
struct mbuf *m_getcl(int, int, int);
void m_copydata(struct mbuf *, int, int, void *);
-struct mbuf *m__free(const char *, int, struct mbuf *);
-void m__freem(const char *, int, struct mbuf *);
-#ifdef DEBUG
-#define m_free(m) m__free(__func__, __LINE__, m)
-#define m_freem(m) m__freem(__func__, __LINE__, m)
-#else
struct mbuf *m_free(struct mbuf *);
void m_freem(struct mbuf *);
-#endif
void m_reclaim(void *, int);
void mbinit(void);
void m_ext_free(struct mbuf *);
Home |
Main Index |
Thread Index |
Old Index