Source-Changes-HG archive

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

[src/trunk]: src/sys/kern - add KASSERTS on functions that don't accept M_COP...



details:   https://anonhg.NetBSD.org/src/rev/9594d71943de
branches:  trunk
changeset: 791380:9594d71943de
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Nov 14 18:54:40 2013 +0000

description:
- add KASSERTS on functions that don't accept M_COPYALL
- compute length for m_copyback0, m_makewritable used from ipf, is using
  M_COPYALL.

diffstat:

 sys/kern/uipc_mbuf.c |  49 ++++++++++++++++++++++++++++---------------------
 1 files changed, 28 insertions(+), 21 deletions(-)

diffs (161 lines):

diff -r adde6ae537b7 -r 9594d71943de sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c      Thu Nov 14 16:53:51 2013 +0000
+++ b/sys/kern/uipc_mbuf.c      Thu Nov 14 18:54:40 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_mbuf.c,v 1.155 2013/11/14 09:21:30 skrll Exp $    */
+/*     $NetBSD: uipc_mbuf.c,v 1.156 2013/11/14 18:54:40 christos 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.155 2013/11/14 09:21:30 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.156 2013/11/14 18:54:40 christos Exp $");
 
 #include "opt_mbuftrace.h"
 #include "opt_nmbclusters.h"
@@ -482,15 +482,17 @@
 void
 m_align(struct mbuf *m, int len)
 {
-       int adjust;
+       int adjust;
+
+       KASSERT(len != M_COPYALL);
 
-       if (m->m_flags & M_EXT)
-              adjust = m->m_ext.ext_size - len;
-       else if (m->m_flags & M_PKTHDR)
-              adjust = MHLEN - len;
-       else
-              adjust = MLEN - len;
-       m->m_data += adjust &~ (sizeof(long)-1);
+       if (m->m_flags & M_EXT)
+               adjust = m->m_ext.ext_size - len;
+       else if (m->m_flags & M_PKTHDR)
+               adjust = MHLEN - len;
+       else
+               adjust = MLEN - len;
+       m->m_data += adjust &~ (sizeof(long)-1);
 }
 
 /*
@@ -507,6 +509,7 @@
        int remainder, space;
        const char *cp = cpv;
 
+       KASSERT(len != M_COPYALL);
        for (m = m0; m->m_next != NULL; m = m->m_next)
                continue;
        remainder = len;
@@ -683,6 +686,7 @@
 {
        struct mbuf *mn;
 
+       KASSERT(len != M_COPYALL);
        mn = m_get(how, m->m_type);
        if (mn == NULL) {
                m_freem(m);
@@ -876,6 +880,7 @@
        int             off0 = off;
        void            *vp0 = vp;
 
+       KASSERT(len != M_COPYALL);
        if (off < 0 || len < 0)
                panic("m_copydata: off %d, len %d", off, len);
        while (off > 0) {
@@ -935,6 +940,7 @@
        struct mbuf *m;
        int count;
 
+       KASSERT(len != M_COPYALL);
        if ((m = mp) == NULL)
                return;
        if (len >= 0) {
@@ -1015,6 +1021,7 @@
        struct mbuf *n = *m0, *m;
        size_t count, space;
 
+       KASSERT(len != M_COPYALL);
        /*
         * If first mbuf has no cluster, and has room for len bytes
         * without shifting current data, pullup into it,
@@ -1072,6 +1079,7 @@
 {
        struct mbuf *m = n;
 
+       KASSERT(len != M_COPYALL);
        if (!m_ensure_contig(&m, len)) {
                KASSERT(m != NULL);
                m_freem(m);
@@ -1094,6 +1102,7 @@
        struct mbuf *m;
        int count, space;
 
+       KASSERT(len != M_COPYALL);
        if (len > (MHLEN - dstoff))
                goto bad;
        m = m_get(M_DONTWAIT, n->m_type);
@@ -1148,6 +1157,7 @@
        struct mbuf *m, *n;
        unsigned len = len0, remain, len_save;
 
+       KASSERT(len0 != M_COPYALL);
        for (m = m0; m && len > m->m_len; m = m->m_next)
                len -= m->m_len;
        if (m == 0)
@@ -1308,6 +1318,7 @@
        int error;
 
        /* don't support chain expansion */
+       KASSERT(len != M_COPYALL);
        KDASSERT(off + len <= m_length(m0));
 
        error = m_copyback0(&m0, off, len, cp,
@@ -1331,23 +1342,15 @@
 {
        int error;
 #if defined(DEBUG)
-       struct mbuf *n;
-       int origlen, reslen;
-
-       origlen = m_length(*mp);
+       int origlen = m_length(*mp);
 #endif /* defined(DEBUG) */
 
-#if 0 /* M_COPYALL is large enough */
-       if (len == M_COPYALL)
-               len = m_length(*mp) - off; /* XXX */
-#endif
-
        error = m_copyback0(mp, off, len, NULL,
            M_COPYBACK0_PRESERVE|M_COPYBACK0_COW, how);
 
 #if defined(DEBUG)
-       reslen = 0;
-       for (n = *mp; n; n = n->m_next)
+       int reslen = 0;
+       for (struct mbuf *n = *mp; n; n = n->m_next)
                reslen += n->m_len;
        if (origlen != reslen)
                panic("m_makewritable: length changed");
@@ -1429,6 +1432,9 @@
        KASSERT((flags & M_COPYBACK0_PRESERVE) == 0 || cp == NULL);
        KASSERT((flags & M_COPYBACK0_COPYBACK) == 0 || cp != NULL);
 
+       if (len == M_COPYALL)
+               len = m_length(*mp0) - off;
+
        /*
         * we don't bother to update "totlen" in the case of M_COPYBACK0_COW,
         * assuming that M_COPYBACK0_EXTEND and M_COPYBACK0_COW are exclusive.
@@ -1624,6 +1630,7 @@
        unsigned int count;
        int rval;
 
+       KASSERT(len != M_COPYALL);
        KASSERT(len >= 0);
        KASSERT(off >= 0);
 



Home | Main Index | Thread Index | Old Index