Source-Changes-HG archive

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

[src/trunk]: src/sys Avoid touching a mbuf after enqueuing it



details:   https://anonhg.NetBSD.org/src/rev/a947e1a3d026
branches:  trunk
changeset: 352365:a947e1a3d026
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Mar 28 08:47:19 2017 +0000

description:
Avoid touching a mbuf after enqueuing it

diffstat:

 sys/arch/arm/gemini/gemini_gmac.c |   6 +++---
 sys/net/if.c                      |  10 ++++++----
 sys/net/if_loop.c                 |   8 ++++----
 sys/net/if_spppsubr.c             |  35 ++++++++++++++++++++---------------
 sys/netisdn/i4b_capi_msgs.c       |   6 +++---
 sys/netisdn/i4b_ipr.c             |  10 ++++------
 sys/netisdn/i4b_isppp.c           |   6 +++---
 7 files changed, 43 insertions(+), 38 deletions(-)

diffs (truncated from 305 to 300 lines):

diff -r 95a9de0ded77 -r a947e1a3d026 sys/arch/arm/gemini/gemini_gmac.c
--- a/sys/arch/arm/gemini/gemini_gmac.c Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/arch/arm/gemini/gemini_gmac.c Tue Mar 28 08:47:19 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gemini_gmac.c,v 1.11 2016/12/15 09:28:02 ozaki-r Exp $ */
+/* $NetBSD: gemini_gmac.c,v 1.12 2017/03/28 08:47:19 ozaki-r Exp $ */
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -49,7 +49,7 @@
 
 #include <sys/gpio.h>
 
-__KERNEL_RCSID(0, "$NetBSD: gemini_gmac.c,v 1.11 2016/12/15 09:28:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gemini_gmac.c,v 1.12 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #define        SWFREEQ_DESCS   256     /* one page worth */
 #define        HWFREEQ_DESCS   256     /* one page worth */
@@ -728,8 +728,8 @@
                d->d_bufaddr = htole32(map->dm_segs->ds_addr);
                for (m0 = hwq->hwq_ifq.ifq_head; m0 != NULL; m0 = m0->m_nextpkt)
                        KASSERT(m0 != m);
+               m->m_len = d - hwq->hwq_base;
                IF_ENQUEUE(&hwq->hwq_ifq, m);
-               m->m_len = d - hwq->hwq_base;
                aprint_debug(
                    "gmac_rxproduce(%p): m=%p %zu@%p=%#x/%#x/%#x/%#x\n", hwq,
                    m, d - hwq->hwq_base, d, d->d_desc0, d->d_desc1,
diff -r 95a9de0ded77 -r a947e1a3d026 sys/net/if.c
--- a/sys/net/if.c      Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/net/if.c      Tue Mar 28 08:47:19 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.388 2017/03/24 11:15:25 ozaki-r Exp $ */
+/*     $NetBSD: if.c,v 1.389 2017/03/28 08:47:19 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.388 2017/03/24 11:15:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.389 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3209,6 +3209,8 @@
 if_transmit(struct ifnet *ifp, struct mbuf *m)
 {
        int s, error;
+       size_t pktlen = m->m_pkthdr.len;
+       bool mcast = (m->m_flags & M_MCAST) != 0;
 
        s = splnet();
 
@@ -3218,8 +3220,8 @@
                goto out;
        }
 
-       ifp->if_obytes += m->m_pkthdr.len;
-       if (m->m_flags & M_MCAST)
+       ifp->if_obytes += pktlen;
+       if (mcast)
                ifp->if_omcasts++;
 
        if ((ifp->if_flags & IFF_OACTIVE) == 0)
diff -r 95a9de0ded77 -r a947e1a3d026 sys/net/if_loop.c
--- a/sys/net/if_loop.c Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/net/if_loop.c Tue Mar 28 08:47:19 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_loop.c,v 1.93 2016/11/22 02:06:00 ozaki-r Exp $     */
+/*     $NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.93 2016/11/22 02:06:00 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -361,10 +361,10 @@
                error = ENOBUFS;
                goto out;
        }
+       ifp->if_ipackets++;
+       ifp->if_ibytes += m->m_pkthdr.len;
        IF_ENQUEUE(ifq, m);
        schednetisr(isr);
-       ifp->if_ipackets++;
-       ifp->if_ibytes += m->m_pkthdr.len;
        splx(s);
 out:
        KERNEL_UNLOCK_ONE(NULL);
diff -r 95a9de0ded77 -r a947e1a3d026 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/net/if_spppsubr.c     Tue Mar 28 08:47:19 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.168 2017/03/28 07:32:16 ozaki-r Exp $         */
+/*     $NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $         */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.168 2017/03/28 07:32:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -716,6 +716,7 @@
 #endif
        int s, error = 0;
        uint16_t protocol;
+       size_t pktlen;
 
        s = splnet();
 
@@ -902,11 +903,11 @@
                h->protocol = protocol;
        }
 
-
+       pktlen = m->m_pkthdr.len;
 #ifdef SPPPSUBR_MPSAFE
        error = if_transmit_lock(ifp, m);
        if (error == 0)
-               ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+               ifp->if_obytes += pktlen + sp->pp_framebytes;
 #else /* !SPPPSUBR_MPSAFE */
        error = ifq_enqueue2(ifp, ifq, m);
 
@@ -921,7 +922,7 @@
                        if_start_lock(ifp);
                        sppp_lock_enter(sp);
                }
-               ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+               ifp->if_obytes += pktlen + sp->pp_framebytes;
        }
 #endif /* !SPPPSUBR_MPSAFE */
        sppp_lock_exit(sp);
@@ -1382,14 +1383,16 @@
                m_freem(m);
                ++ifp->if_oerrors;
                return;
-       } else
-               IF_ENQUEUE(&sp->pp_cpq, m);
+       }
+
+       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+       IF_ENQUEUE(&sp->pp_cpq, m);
+
        if (! (ifp->if_flags & IFF_OACTIVE)) {
                sppp_lock_exit(sp);
                if_start_lock(ifp);
                sppp_lock_enter(sp);
        }
-       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
 }
 
 /*
@@ -1452,16 +1455,16 @@
                m_freem(m);
                ++ifp->if_oerrors;
                return;
-       } else
-               IF_ENQUEUE(&sp->pp_cpq, m);
+       }
+
+       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+       IF_ENQUEUE(&sp->pp_cpq, m);
 
        if (! (ifp->if_flags & IFF_OACTIVE)) {
                sppp_lock_exit(sp);
                if_start_lock(ifp);
                sppp_lock_enter(sp);
        }
-
-       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
 }
 
 /*
@@ -5073,14 +5076,16 @@
                m_freem(m);
                ++ifp->if_oerrors;
                return;
-       } else
-               IF_ENQUEUE(&sp->pp_cpq, m);
+       }
+
+       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+       IF_ENQUEUE(&sp->pp_cpq, m);
+
        if (! (ifp->if_flags & IFF_OACTIVE)) {
                sppp_lock_exit(sp);
                if_start_lock(ifp);
                sppp_lock_enter(sp);
        }
-       ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
 }
 
 /*
diff -r 95a9de0ded77 -r a947e1a3d026 sys/netisdn/i4b_capi_msgs.c
--- a/sys/netisdn/i4b_capi_msgs.c       Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/netisdn/i4b_capi_msgs.c       Tue Mar 28 08:47:19 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i4b_capi_msgs.c,v 1.8 2014/03/20 20:43:35 christos Exp $       */
+/*     $NetBSD: i4b_capi_msgs.c,v 1.9 2017/03/28 08:47:19 ozaki-r Exp $        */
 
 /*
  * Copyright (c) 2001-2003 Cubical Solutions Ltd. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i4b_capi_msgs.c,v 1.8 2014/03/20 20:43:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i4b_capi_msgs.c,v 1.9 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -801,8 +801,8 @@
            /* Telephony drivers use rx_queue */
 
            if (!IF_QFULL(&sc->sc_bchan[bch].rx_queue)) {
+               sc->sc_bchan[bch].rxcount += m_in->m_next->m_len;
                IF_ENQUEUE(&sc->sc_bchan[bch].rx_queue, m_in->m_next);
-               sc->sc_bchan[bch].rxcount += m_in->m_next->m_len;
                m_in->m_next = NULL; /* driver frees */
            }
 
diff -r 95a9de0ded77 -r a947e1a3d026 sys/netisdn/i4b_ipr.c
--- a/sys/netisdn/i4b_ipr.c     Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/netisdn/i4b_ipr.c     Tue Mar 28 08:47:19 2017 +0000
@@ -27,7 +27,7 @@
  *     i4b_ipr.c - isdn4bsd IP over raw HDLC ISDN network driver
  *     ---------------------------------------------------------
  *
- *     $Id: i4b_ipr.c,v 1.41 2017/01/24 09:05:28 ozaki-r Exp $
+ *     $Id: i4b_ipr.c,v 1.42 2017/03/28 08:47:19 ozaki-r Exp $
  *
  * $FreeBSD$
  *
@@ -59,7 +59,7 @@
  *---------------------------------------------------------------------------*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i4b_ipr.c,v 1.41 2017/01/24 09:05:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i4b_ipr.c,v 1.42 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #include "irip.h"
 #include "opt_irip.h"
@@ -1152,11 +1152,9 @@
                }
                else
                {
+                       sc->sc_if.if_obytes += m->m_pkthdr.len;
+                       sc->sc_if.if_opackets++;
                        IF_ENQUEUE(sc->sc_ilt->tx_queue, m);
-
-                       sc->sc_if.if_obytes += m->m_pkthdr.len;
-
-                       sc->sc_if.if_opackets++;
                }
        }
 
diff -r 95a9de0ded77 -r a947e1a3d026 sys/netisdn/i4b_isppp.c
--- a/sys/netisdn/i4b_isppp.c   Tue Mar 28 07:32:16 2017 +0000
+++ b/sys/netisdn/i4b_isppp.c   Tue Mar 28 08:47:19 2017 +0000
@@ -34,7 +34,7 @@
  *     the "cx" driver for Cronyx's HDLC-in-hardware device).  This driver
  *     is only the glue between sppp and i4b.
  *
- *     $Id: i4b_isppp.c,v 1.30 2016/12/15 09:28:06 ozaki-r Exp $
+ *     $Id: i4b_isppp.c,v 1.31 2017/03/28 08:47:19 ozaki-r Exp $
  *
  * $FreeBSD$
  *
@@ -43,7 +43,7 @@
  *---------------------------------------------------------------------------*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.30 2016/12/15 09:28:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.31 2017/03/28 08:47:19 ozaki-r Exp $");
 
 #ifndef __NetBSD__
 #define USE_ISPPP
@@ -424,12 +424,12 @@
                }
                else
                {
-                       IF_ENQUEUE(sc->sc_ilt->tx_queue, m);
 #if 0
                        sc->sc_sp.pp_if.if_obytes += m->m_pkthdr.len;
 #endif
                        sc->sc_outb += m->m_pkthdr.len;



Home | Main Index | Thread Index | Old Index