Module Name:    src
Committed By:   maxv
Date:           Mon Jan  1 12:09:56 UTC 2018

Modified Files:
        src/sys/kern: uipc_mbuf.c
        src/sys/sys: mbuf.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/kern/uipc_mbuf.c
cvs rdiff -u -r1.172 -r1.173 src/sys/sys/mbuf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_mbuf.c
diff -u src/sys/kern/uipc_mbuf.c:1.174 src/sys/kern/uipc_mbuf.c:1.175
--- src/sys/kern/uipc_mbuf.c:1.174	Sun Dec 31 06:57:12 2017
+++ src/sys/kern/uipc_mbuf.c	Mon Jan  1 12:09:56 2018
@@ -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 @@ m_claim(struct mbuf *m, struct mowner *m
 #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.
- */
-#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)
-
+ * Free a single mbuf and associated external storage. Return the
+ * successor, if any.
+ */
 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);
 
-void
-m__freem(const char *f, int l, struct mbuf *m)
-{
-	struct mbuf *n;
+	if (m->m_flags & M_PKTHDR)
+		m_tag_delete_chain(m, NULL);
 
-	if (m == NULL)
-		return;
-	do {
-		MFREE(f, l, m, n);
-		m = n;
-	} while (m);
-}
+	n = m->m_next;
 
-#undef m_free
-struct mbuf *m_free(struct mbuf *);
-struct mbuf *
-m_free(struct mbuf *m)
-{
-	return m__free(__func__, __LINE__, m);
+	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;
 }
 
-#undef m_freem
-void m_freem(struct mbuf *);
 void
 m_freem(struct mbuf *m)
 {
-	m__freem(__func__, __LINE__, m);
+	if (m == NULL)
+		return;
+	do {
+		m = m_free(m);
+	} while (m);
 }

Index: src/sys/sys/mbuf.h
diff -u src/sys/sys/mbuf.h:1.172 src/sys/sys/mbuf.h:1.173
--- src/sys/sys/mbuf.h:1.172	Thu Nov  9 22:34:07 2017
+++ src/sys/sys/mbuf.h	Mon Jan  1 12:09:56 2018
@@ -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 @@ struct	mbuf *m_copyback_cow(struct mbuf 
 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 *);

Reply via email to