Get rid of the twisted MFREE() macro entirely.

Reviewed by:	dg, bmilekic
MFC after:	3 days
This commit is contained in:
Matthew Dillon 2002-02-05 02:00:56 +00:00
parent 14102e47d3
commit ecde8f7c29
15 changed files with 67 additions and 95 deletions

View File

@ -869,12 +869,11 @@ cnw_start(ifp)
* 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 @@ cnw_transmit(sc, m0)
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 @@ cnw_transmit(sc, m0)
mptr += n;
mbytes -= n;
}
MFREE(m, m0);
m = m0;
m = m_free(m);
}
/* Issue transmit command */

View File

@ -833,9 +833,11 @@ lnc_tint(struct lnc_softc *sc)
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 @@ lnc_start(struct ifnet *ifp)
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;
}
}
}

View File

@ -390,7 +390,7 @@ vxstart(ifp)
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 @@ vxstart(ifp)
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 @@ vxstart(ifp)
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 @@ vxstart(ifp)
}
}
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 @@ vxstart(ifp)
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 @@ vxstart(ifp)
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 */

View File

@ -131,14 +131,9 @@ m_getm(struct mbuf *m, int len, int how, int type)
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);
}
}
/*

View File

@ -777,7 +777,7 @@ sbdrop(sb, len)
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 @@ sbdrop(sb, len)
}
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 @@ void
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);
}
}

View File

@ -809,7 +809,7 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
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 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
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)

View File

@ -777,7 +777,7 @@ sbdrop(sb, len)
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 @@ sbdrop(sb, len)
}
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 @@ void
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);
}
}

View File

@ -1401,9 +1401,10 @@ ppp_inproc(sc, m)
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;

View File

@ -601,7 +601,6 @@ slstart(tp)
register u_char *cp;
register struct ip *ip;
int s;
struct mbuf *m2;
register int len = 0;
for (;;) {
@ -761,8 +760,7 @@ slstart(tp)
sc->sc_if.if_obytes += 2;
}
}
MFREE(m, m2);
m = m2;
m = m_free(m);
}
if (putc(FRAME_END, &tp->t_outq)) {

View File

@ -768,7 +768,7 @@ tapread(dev, uio, flag)
{
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 @@ tapread(dev, uio, flag)
/* 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 @@ tapread(dev, uio, flag)
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);

View File

@ -636,7 +636,7 @@ tunread(dev_t dev, struct uio *uio, int flag)
{
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 @@ tunread(dev_t dev, struct uio *uio, int flag)
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 @@ tunread(dev_t dev, struct uio *uio, int flag)
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;
}

View File

@ -549,7 +549,6 @@ pppasyncstart(sc)
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 @@ pppasyncstart(sc)
}
/* 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;

View File

@ -472,15 +472,12 @@ nga_rcv_sync(const sc_p sc, item_p item)
/* 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 @@ nga_rcv_async(const sc_p sc, item_p item)
sc->fcs = PPP_FCS(sc->fcs, ch);
}
}
MFREE(m, n);
m = n;
m = m_free(m);
}
if (item)
NG_FREE_ITEM(item);

View File

@ -422,7 +422,6 @@ ngt_start(struct tty *tp)
/* Send as much of it as possible */
while (m) {
struct mbuf *m2;
int sent;
sent = m->m_len
@ -431,8 +430,7 @@ ngt_start(struct tty *tp)
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 */

View File

@ -284,10 +284,6 @@ struct mbstat {
#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).