Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Feb 2002 20:00:08 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        hackers@freebsd.org
Subject:   Patch to remove MFREE() macro entirely
Message-ID:  <200202030400.g13408C59494@apollo.backplane.com>

next in thread | raw e-mail | index | archive | help
    Oh what a tangled web we weave.  This should be really easy for people
    to take a quick look at to see if I made any mistakes.  I'm basically
    untangling the (small) mess that people made of the code while trying to
    use the MFREE() macro over the last N years.

    If nobody sees any problems it will go into -current next week some
    time and then be MFC'd to stable.

    After that I'll deal with the two or three major softupdates-related
    patches that need to be MFC'd and perhaps the vrele() bug, and after
    I'll hopefully be able to do some work on -current.  Alfred has been
    very patient I know.

    It would also be nice if someone took a more detailed look at the
    one 'XXX' comment I have in there for the LNC driver.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>

Index: dev/cnw/if_cnw.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/cnw/if_cnw.c,v
retrieving revision 1.3
diff -u -r1.3 if_cnw.c
--- dev/cnw/if_cnw.c	8 May 2001 23:57:32 -0000	1.3
+++ dev/cnw/if_cnw.c	3 Feb 2002 03:17:59 -0000
@@ -869,12 +869,11 @@
  * Transmit a packet.
  */
 void
-cnw_transmit(sc, m0)
+cnw_transmit(sc, m)
 	struct cnw_softc *sc;
-	struct mbuf *m0;
+	struct mbuf *m;
 {
 	int buffer, bufsize, bufoffset, bufptr, bufspace, len, mbytes, n;
-	struct mbuf *m;
 	u_int8_t *mptr;
 
 	/* Get buffer info from card */
@@ -891,7 +890,7 @@
 	bufptr = sc->sc_memoff + buffer + bufoffset;
 	bufspace = bufsize;
 	len = 0;
-	for (m = m0; m; ) {
+	while (m) {
 		mptr = mtod(m, u_int8_t *);
 		mbytes = m->m_len;
 		len += mbytes;
@@ -914,8 +913,7 @@
 			mptr += n;
 			mbytes -= n;
 		}
-		MFREE(m, m0);
-		m = m0;
+		m = m_free(m);
 	}
 
 	/* Issue transmit command */
Index: dev/lnc/if_lnc.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/lnc/if_lnc.c,v
retrieving revision 1.89
diff -u -r1.89 if_lnc.c
--- dev/lnc/if_lnc.c	4 Jul 2001 13:00:19 -0000	1.89
+++ dev/lnc/if_lnc.c	3 Feb 2002 03:20:18 -0000
@@ -833,9 +833,11 @@
 					sc->mbuf_count++;
 					start->buff.mbuf = 0;
 				} else {
-					struct mbuf *junk;
-					MFREE(start->buff.mbuf, junk);
-					start->buff.mbuf = 0;
+					/*
+					 * XXX should this be m_freem()?
+					 */
+					m_free(start->buff.mbuf);
+					start->buff.mbuf = NULL;
 				}
 			}
 			sc->pending_transmits--;
@@ -1308,8 +1310,8 @@
 						m->m_len -= chunk;
 						m->m_data += chunk;
 						if (m->m_len <= 0) {
-							MFREE(m, head->m_next);
-							m = head->m_next;
+							m = m_free(m);
+							head->m_next = m;
 						}
 					}
 				}
Index: dev/vx/if_vx.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/vx/if_vx.c,v
retrieving revision 1.34
diff -u -r1.34 if_vx.c
--- dev/vx/if_vx.c	19 Jul 2001 02:16:01 -0000	1.34
+++ dev/vx/if_vx.c	3 Feb 2002 03:22:42 -0000
@@ -390,7 +390,7 @@
     struct ifnet *ifp;
 {
     register struct vx_softc *sc = ifp->if_softc;
-    register struct mbuf *m, *m0;
+    register struct mbuf *m;
     int sh, len, pad;
 
     /* Don't transmit if interface is busy or not running */
@@ -399,14 +399,14 @@
 
 startagain:
     /* Sneak a peek at the next packet */
-    m0 = ifp->if_snd.ifq_head;
-    if (m0 == 0) {
+    m = ifp->if_snd.ifq_head;
+    if (m == NULL) {
 	return;
     }
     /* We need to use m->m_pkthdr.len, so require the header */
-     if ((m0->m_flags & M_PKTHDR) == 0)
+     if ((m->m_flags & M_PKTHDR) == 0)
 	panic("vxstart: no header mbuf");
-     len = m0->m_pkthdr.len;
+     len = m->m_pkthdr.len;
 
      pad = (4 - len) & 3;
 
@@ -418,8 +418,8 @@
     if (len + pad > ETHER_MAX_LEN) {
 	/* packet is obviously too large: toss it */
 	++ifp->if_oerrors;
-	IF_DEQUEUE(&ifp->if_snd, m0);
-	m_freem(m0);
+	IF_DEQUEUE(&ifp->if_snd, m);
+	m_freem(m);
 	goto readcheck;
     }
     VX_BUSY_WAIT;
@@ -433,17 +433,16 @@
 	}
     }
     CSR_WRITE_2(sc,  VX_COMMAND, SET_TX_AVAIL_THRESH | (8188 >> 2));
-    IF_DEQUEUE(&ifp->if_snd, m0);
-    if (m0 == 0) {		/* not really needed */
+    IF_DEQUEUE(&ifp->if_snd, m);
+    if (m == NULL) 		/* not really needed */
 	return;
-    }
 
     VX_BUSY_WAIT;
     CSR_WRITE_2(sc,  VX_COMMAND, SET_TX_START_THRESH |
 	((len / 4 + sc->tx_start_thresh) >> 2));
 
     if (sc->arpcom.ac_if.if_bpf) {
-	bpf_mtap(&sc->arpcom.ac_if, m0);
+	bpf_mtap(&sc->arpcom.ac_if, m);
     }
 
     /*
@@ -454,7 +453,7 @@
 
     CSR_WRITE_4(sc,  VX_W1_TX_PIO_WR_1, len | TX_INDICATE);
 
-    for (m = m0; m != 0;) {
+    while (m) {
         if (m->m_len > 3)
 	    bus_space_write_multi_4(sc->vx_btag, sc->vx_bhandle,
 		VX_W1_TX_PIO_WR_1, (u_int32_t *)mtod(m, caddr_t), m->m_len / 4);
@@ -462,8 +461,7 @@
 	    bus_space_write_multi_1(sc->vx_btag, sc->vx_bhandle,
 		VX_W1_TX_PIO_WR_1,
 		mtod(m, caddr_t) + (m->m_len & ~3) , m->m_len & 3);
-        MFREE(m, m0);
-        m = m0;
+	m = m_free(m);
     }
     while (pad--)
 	CSR_WRITE_1(sc,  VX_W1_TX_PIO_WR_1, 0);	/* Padding */
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.89
diff -u -r1.89 uipc_mbuf.c
--- kern/uipc_mbuf.c	10 Dec 2001 05:51:45 -0000	1.89
+++ kern/uipc_mbuf.c	3 Feb 2002 03:27:35 -0000
@@ -131,14 +131,9 @@
 void
 m_freem(struct mbuf *m)
 {
-	struct mbuf *n;
-
-	if (m == NULL)
-		return;
-	do {
-		MFREE(m, n);
-		m = n;
-	} while (m);
+	while (m) {
+		m = m_free(m);
+	}
 }
 
 /*
Index: kern/uipc_socket.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.108
diff -u -r1.108 uipc_socket.c
--- kern/uipc_socket.c	14 Jan 2002 22:03:48 -0000	1.108
+++ kern/uipc_socket.c	3 Feb 2002 03:25:48 -0000
@@ -809,7 +809,7 @@
 			m = m->m_next;
 		} else {
 			sbfree(&so->so_rcv, m);
-			MFREE(m, so->so_rcv.sb_mb);
+			so->so_rcv.sb_mb = m_free(m);
 			m = so->so_rcv.sb_mb;
 		}
 	}
@@ -893,7 +893,7 @@
 					so->so_rcv.sb_mb = m = m->m_next;
 					*mp = (struct mbuf *)0;
 				} else {
-					MFREE(m, so->so_rcv.sb_mb);
+					so->so_rcv.sb_mb = m_free(m);
 					m = so->so_rcv.sb_mb;
 				}
 				if (m)
Index: kern/uipc_socket2.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/uipc_socket2.c,v
retrieving revision 1.82
diff -u -r1.82 uipc_socket2.c
--- kern/uipc_socket2.c	9 Jan 2002 01:45:17 -0000	1.82
+++ kern/uipc_socket2.c	3 Feb 2002 03:28:31 -0000
@@ -777,7 +777,7 @@
 	register struct sockbuf *sb;
 	register int len;
 {
-	register struct mbuf *m, *mn;
+	register struct mbuf *m;
 	struct mbuf *next;
 
 	next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
@@ -797,13 +797,11 @@
 		}
 		len -= m->m_len;
 		sbfree(sb, m);
-		MFREE(m, mn);
-		m = mn;
+		m = m_free(m);
 	}
 	while (m && m->m_len == 0) {
 		sbfree(sb, m);
-		MFREE(m, mn);
-		m = mn;
+		m = m_free(m);
 	}
 	if (m) {
 		sb->sb_mb = m;
@@ -820,15 +818,14 @@
 sbdroprecord(sb)
 	register struct sockbuf *sb;
 {
-	register struct mbuf *m, *mn;
+	register struct mbuf *m;
 
 	m = sb->sb_mb;
 	if (m) {
 		sb->sb_mb = m->m_nextpkt;
 		do {
 			sbfree(sb, m);
-			MFREE(m, mn);
-			m = mn;
+			m = m_free(m);
 		} while (m);
 	}
 }
Index: net/if_ppp.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_ppp.c,v
retrieving revision 1.73
diff -u -r1.73 if_ppp.c
--- net/if_ppp.c	8 Jan 2002 10:30:09 -0000	1.73
+++ net/if_ppp.c	3 Feb 2002 03:29:11 -0000
@@ -1401,9 +1401,10 @@
 	if (m->m_len <= M_TRAILINGSPACE(mp)) {
 	    bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
 	    mp->m_len += m->m_len;
-	    MFREE(m, mp->m_next);
-	} else
+	    mp->m_next = m_free(m);
+	} else {
 	    mp->m_next = m;
+	}
 	m = mp;
 	ilen += hlen - xlen;
 
Index: net/if_sl.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_sl.c,v
retrieving revision 1.97
diff -u -r1.97 if_sl.c
--- net/if_sl.c	8 Jan 2002 10:30:09 -0000	1.97
+++ net/if_sl.c	3 Feb 2002 03:29:40 -0000
@@ -601,7 +601,6 @@
 	register u_char *cp;
 	register struct ip *ip;
 	int s;
-	struct mbuf *m2;
 	register int len = 0;
 
 	for (;;) {
@@ -761,8 +760,7 @@
 					sc->sc_if.if_obytes += 2;
 				}
 			}
-			MFREE(m, m2);
-			m = m2;
+			m = m_free(m);
 		}
 
 		if (putc(FRAME_END, &tp->t_outq)) {
Index: net/if_tap.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_tap.c,v
retrieving revision 1.12
diff -u -r1.12 if_tap.c
--- net/if_tap.c	14 Dec 2001 19:29:30 -0000	1.12
+++ net/if_tap.c	3 Feb 2002 03:30:41 -0000
@@ -768,7 +768,7 @@
 {
 	struct tap_softc	*tp = dev->si_drv1;
 	struct ifnet		*ifp = &tp->tap_if;
-	struct mbuf		*m = NULL, *m0 = NULL;
+	struct mbuf		*m = NULL;
 	int			 error = 0, len, s;
 
 	TAPDEBUG("%s%d reading, minor = %#x\n", 
@@ -786,10 +786,10 @@
 	/* sleep until we get a packet */
 	do {
 		s = splimp();
-		IF_DEQUEUE(&ifp->if_snd, m0);
+		IF_DEQUEUE(&ifp->if_snd, m);
 		splx(s);
 
-		if (m0 == NULL) {
+		if (m == NULL) {
 			if (flag & IO_NDELAY)
 				return (EWOULDBLOCK);
 			
@@ -798,27 +798,26 @@
 			if (error)
 				return (error);
 		}
-	} while (m0 == NULL);
+	} while (m == NULL);
 
 	/* feed packet to bpf */
 	if (ifp->if_bpf != NULL)
-		bpf_mtap(ifp, m0);
+		bpf_mtap(ifp, m);
 
 	/* xfer packet to user space */
-	while ((m0 != NULL) && (uio->uio_resid > 0) && (error == 0)) {
-		len = min(uio->uio_resid, m0->m_len);
+	while ((m != NULL) && (uio->uio_resid > 0) && (error == 0)) {
+		len = min(uio->uio_resid, m->m_len);
 		if (len == 0)
 			break;
 
-		error = uiomove(mtod(m0, caddr_t), len, uio);
-		MFREE(m0, m);
-		m0 = m;
+		error = uiomove(mtod(m, caddr_t), len, uio);
+		m = m_free(m);
 	}
 
-	if (m0 != NULL) {
+	if (m != NULL) {
 		TAPDEBUG("%s%d dropping mbuf, minor = %#x\n", ifp->if_name, 
 			ifp->if_unit, minor(dev));
-		m_freem(m0);
+		m_freem(m);
 	}
 
 	return (error);
Index: net/if_tun.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_tun.c,v
retrieving revision 1.100
diff -u -r1.100 if_tun.c
--- net/if_tun.c	21 Sep 2001 22:46:54 -0000	1.100
+++ net/if_tun.c	3 Feb 2002 03:33:09 -0000
@@ -636,7 +636,7 @@
 {
 	struct tun_softc *tp = dev->si_drv1;
 	struct ifnet	*ifp = &tp->tun_if;
-	struct mbuf	*m, *m0;
+	struct mbuf	*m;
 	int		error=0, len, s;
 
 	TUNDEBUG ("%s%d: read\n", ifp->if_name, ifp->if_unit);
@@ -650,8 +650,8 @@
 
 	s = splimp();
 	do {
-		IF_DEQUEUE(&ifp->if_snd, m0);
-		if (m0 == 0) {
+		IF_DEQUEUE(&ifp->if_snd, m);
+		if (m == NULL) {
 			if (flag & IO_NDELAY) {
 				splx(s);
 				return EWOULDBLOCK;
@@ -663,20 +663,19 @@
 				return error;
 			}
 		}
-	} while (m0 == 0);
+	} while (m == NULL);
 	splx(s);
 
-	while (m0 && uio->uio_resid > 0 && error == 0) {
-		len = min(uio->uio_resid, m0->m_len);
+	while (m && uio->uio_resid > 0 && error == 0) {
+		len = min(uio->uio_resid, m->m_len);
 		if (len != 0)
-			error = uiomove(mtod(m0, caddr_t), len, uio);
-		MFREE(m0, m);
-		m0 = m;
+			error = uiomove(mtod(m, caddr_t), len, uio);
+		m = m_free(m);
 	}
 
-	if (m0) {
+	if (m) {
 		TUNDEBUG("%s%d: Dropping mbuf\n", ifp->if_name, ifp->if_unit);
-		m_freem(m0);
+		m_freem(m);
 	}
 	return error;
 }
Index: net/ppp_tty.c
===================================================================
RCS file: /home/ncvs/src/sys/net/ppp_tty.c,v
retrieving revision 1.47
diff -u -r1.47 ppp_tty.c
--- net/ppp_tty.c	12 Sep 2001 08:37:51 -0000	1.47
+++ net/ppp_tty.c	3 Feb 2002 03:33:32 -0000
@@ -549,7 +549,6 @@
     register int len;
     register u_char *start, *stop, *cp;
     int n, ndone, done, idle;
-    struct mbuf *m2;
     int s;
 
     idle = 0;
@@ -687,8 +686,7 @@
 	    }
 
 	    /* Finished with this mbuf; free it and move on. */
-	    MFREE(m, m2);
-	    m = m2;
+	    m = m_free(m);
 	    if (m == NULL) {
 		/* Finished a packet */
 		break;
Index: netgraph/ng_async.c
===================================================================
RCS file: /home/ncvs/src/sys/netgraph/ng_async.c,v
retrieving revision 1.17
diff -u -r1.17 ng_async.c
--- netgraph/ng_async.c	10 Dec 2001 08:09:47 -0000	1.17
+++ netgraph/ng_async.c	3 Feb 2002 03:33:55 -0000
@@ -472,15 +472,12 @@
 
 	/* Add packet payload */
 	while (m != NULL) {
-		struct mbuf *n;
-
 		while (m->m_len > 0) {
 			ADD_BYTE(*mtod(m, u_char *));
 			m->m_data++;
 			m->m_len--;
 		}
-		MFREE(m, n);
-		m = n;
+		m = m_free(m);
 	}
 
 	/* Add checksum and final sync flag */
@@ -597,8 +594,7 @@
 				sc->fcs = PPP_FCS(sc->fcs, ch);
 			}
 		}
-		MFREE(m, n);
-		m = n;
+		m = m_free(m);
 	}
 	if (item)
 		NG_FREE_ITEM(item);
Index: netgraph/ng_tty.c
===================================================================
RCS file: /home/ncvs/src/sys/netgraph/ng_tty.c,v
retrieving revision 1.21
diff -u -r1.21 ng_tty.c
--- netgraph/ng_tty.c	10 Dec 2001 08:09:47 -0000	1.21
+++ netgraph/ng_tty.c	3 Feb 2002 03:34:30 -0000
@@ -422,7 +422,6 @@
 
 		/* Send as much of it as possible */
 		while (m) {
-			struct mbuf *m2;
 			int     sent;
 
 			sent = m->m_len
@@ -431,8 +430,7 @@
 			m->m_len -= sent;
 			if (m->m_len > 0)
 				break;	/* device can't take no more */
-			MFREE(m, m2);
-			m = m2;
+			m = m_free(m);
 		}
 
 		/* Put remainder of mbuf chain (if any) back on queue */
Index: sys/mbuf.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/mbuf.h,v
retrieving revision 1.88
diff -u -r1.88 mbuf.h
--- sys/mbuf.h	23 Dec 2001 22:04:08 -0000	1.88
+++ sys/mbuf.h	3 Feb 2002 03:26:43 -0000
@@ -284,10 +284,6 @@
 #define	MCLGET(m, how)		m_clget((m), (how))
 #define	MEXTADD(m, buf, size, free, args, flags, type) 			\
     m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type))
-#define	MFREE(m, n) do {						\
-	(n) = m_free((m));						\
-	(m) = NULL;							\
-} while (0)
 
 /*
  * MEXTFREE(m): disassociate (and possibly free) an external object from (m).

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202030400.g13408C59494>