Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Handle M_EXT with M_BUFADDR, and introduce M_BUFSIZE. Us...



details:   https://anonhg.NetBSD.org/src/rev/e974bd3ad0c5
branches:  trunk
changeset: 454480:e974bd3ad0c5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Sep 18 16:18:12 2019 +0000

description:
Handle M_EXT with M_BUFADDR, and introduce M_BUFSIZE. Use them to dedup
code.

diffstat:

 sys/kern/uipc_mbuf.c |  25 ++++++-------------------
 sys/sys/mbuf.h       |  41 ++++++++++++++++-------------------------
 2 files changed, 22 insertions(+), 44 deletions(-)

diffs (120 lines):

diff -r c35a5eacf5b8 -r e974bd3ad0c5 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c      Wed Sep 18 15:33:32 2019 +0000
+++ b/sys/kern/uipc_mbuf.c      Wed Sep 18 16:18:12 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_mbuf.c,v 1.232 2019/01/17 02:47:15 knakahara Exp $        */
+/*     $NetBSD: uipc_mbuf.c,v 1.233 2019/09/18 16:18:12 maxv Exp $     */
 
 /*
  * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.232 2019/01/17 02:47:15 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.233 2019/09/18 16:18:12 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
@@ -1768,12 +1768,7 @@
        KASSERT(len != M_COPYALL);
        KASSERT(M_LEADINGSPACE(m) == 0);
 
-       if (m->m_flags & M_EXT)
-               buflen = m->m_ext.ext_size;
-       else if (m->m_flags & M_PKTHDR)
-               buflen = MHLEN;
-       else
-               buflen = MLEN;
+       buflen = M_BUFSIZE(m);
 
        KASSERT(len <= buflen);
        adjust = buflen - len;
@@ -2210,20 +2205,12 @@
 
                dat = n->m_data;
                len = n->m_len;
-
-               if (n->m_flags & M_EXT) {
-                       low = n->m_ext.ext_buf;
-                       high = low + n->m_ext.ext_size;
-               } else if (n->m_flags & M_PKTHDR) {
-                       low = n->m_pktdat;
-                       high = low + MHLEN;
-               } else {
-                       low = n->m_dat;
-                       high = low + MLEN;
-               }
                if (__predict_false(dat + len < dat)) {
                        panic("%s: incorrect length (len = %d)", __func__, len);
                }
+
+               low = M_BUFADDR(n);
+               high = low + M_BUFSIZE(n);
                if (__predict_false((dat < low) || (dat + len > high))) {
                        panic("%s: m_data not in packet"
                            "(dat = %p, len = %d, low = %p, high = %p)",
diff -r c35a5eacf5b8 -r e974bd3ad0c5 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Wed Sep 18 15:33:32 2019 +0000
+++ b/sys/sys/mbuf.h    Wed Sep 18 16:18:12 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.220 2019/08/25 16:38:20 rmind Exp $ */
+/*     $NetBSD: mbuf.h,v 1.221 2019/09/18 16:18:12 maxv Exp $  */
 
 /*
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -499,18 +499,23 @@
        mowner_ref((m), M_EXT);                                         \
 } while (/* CONSTCOND */ 0)
 
+#define M_BUFADDR(m)                                                   \
+       (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_buf :                  \
+           ((m)->m_flags & M_PKTHDR) ? (m)->m_pktdat : (m)->m_dat)
+
+#define M_BUFSIZE(m)                                                   \
+       (((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size :                 \
+           ((m)->m_flags & M_PKTHDR) ? MHLEN : MLEN)
+
+#define MRESETDATA(m)  (m)->m_data = M_BUFADDR(m)
+
 /*
- * Reset the data pointer on an mbuf.
+ * Compute the offset of the beginning of the data buffer of a non-ext
+ * mbuf.
  */
-#define MRESETDATA(m)                                                  \
-do {                                                                   \
-       if ((m)->m_flags & M_EXT)                                       \
-               (m)->m_data = (m)->m_ext.ext_buf;                       \
-       else if ((m)->m_flags & M_PKTHDR)                               \
-               (m)->m_data = (m)->m_pktdat;                            \
-       else                                                            \
-               (m)->m_data = (m)->m_dat;                               \
-} while (/* CONSTCOND */ 0)
+#define M_BUFOFFSET(m)                                                 \
+       (((m)->m_flags & M_PKTHDR) ?                                    \
+        offsetof(struct mbuf, m_pktdat) : offsetof(struct mbuf, m_dat))
 
 /*
  * Determine if an mbuf's data area is read-only.  This is true
@@ -556,20 +561,6 @@
        (M_READONLY((m)) ? 0 : _M_TRAILINGSPACE((m)))
 
 /*
- * Compute the address of an mbuf's data area.
- */
-#define M_BUFADDR(m)                                                   \
-       (((m)->m_flags & M_PKTHDR) ? (m)->m_pktdat : (m)->m_dat)
-
-/*
- * Compute the offset of the beginning of the data buffer of a non-ext
- * mbuf.
- */
-#define M_BUFOFFSET(m)                                                 \
-       (((m)->m_flags & M_PKTHDR) ?                                    \
-        offsetof(struct mbuf, m_pktdat) : offsetof(struct mbuf, m_dat))
-
-/*
  * Arrange to prepend space of size plen to mbuf m.
  * If a new mbuf must be allocated, how specifies whether to wait.
  * If how is M_DONTWAIT and allocation fails, the original mbuf chain



Home | Main Index | Thread Index | Old Index