diff --git a/sys/dev/ic/i82586.c b/sys/dev/ic/i82586.c index 4ec31cdaf16c..31da2d3be98d 100644 --- a/sys/dev/ic/i82586.c +++ b/sys/dev/ic/i82586.c @@ -1,4 +1,4 @@ -/* $NetBSD: i82586.c,v 1.18 1998/08/15 04:42:42 mycroft Exp $ */ +/* $NetBSD: i82586.c,v 1.19 1998/12/12 16:58:10 mycroft Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -1081,14 +1081,14 @@ ieget(sc, ehp, to_bpf, head, totlen) int head; int totlen; { - struct mbuf *top, **mp, *m; + struct mbuf *m, *m0, *newm; int len, resid; int thisrboff, thismboff; /* * Snarf the Ethernet header. */ - (sc->memcopyin)(sc, ehp, IE_RBUF_ADDR(sc,head), sizeof *ehp); + (sc->memcopyin)(sc, ehp, IE_RBUF_ADDR(sc, head), sizeof *ehp); /* * As quickly as possible, check if this packet is for us. @@ -1105,43 +1105,39 @@ ieget(sc, ehp, to_bpf, head, totlen) resid = totlen -= (thisrboff = sizeof *ehp); - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) return (0); - m->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if; - m->m_pkthdr.len = totlen; + m0->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if; + m0->m_pkthdr.len = totlen; len = MHLEN; - top = 0; - mp = ⊤ + m = m0; /* * This loop goes through and allocates mbufs for all the data we will * be copying in. It does not actually do the copying yet. */ while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return (0); - } - len = MLEN; - } if (totlen >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_freem(top); - return (0); - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } + m->m_len = len = min(totlen, len); + totlen -= len; - *mp = m; - mp = &m->m_next; + if (totlen > 0) { + MGET(newm, M_DONTWAIT, MT_DATA); + if (newm == 0) + goto bad; + len = MLEN; + m = m->m_next = newm; + } } - m = top; + m = m0; thismboff = 0; /* @@ -1178,7 +1174,11 @@ ieget(sc, ehp, to_bpf, head, totlen) * we have now copied everything in from the shared memory. * This means that we are done. */ - return (top); + return (m0); + +bad: + m_freem(m0); + return (0); } /* diff --git a/sys/dev/ic/lance.c b/sys/dev/ic/lance.c index 0f6404899f77..88cd81845c17 100644 --- a/sys/dev/ic/lance.c +++ b/sys/dev/ic/lance.c @@ -1,4 +1,4 @@ -/* $NetBSD: lance.c,v 1.4 1998/12/09 07:36:51 leo Exp $ */ +/* $NetBSD: lance.c,v 1.5 1998/12/12 16:58:10 mycroft Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -408,53 +408,52 @@ lance_get(sc, boff, totlen) struct lance_softc *sc; int boff, totlen; { - register struct mbuf *m; - struct mbuf *top, **mp; + struct mbuf *m, *m0, *newm; int len; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) return (0); - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; + m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.len = totlen; len = MHLEN; - top = 0; - mp = ⊤ + m = m0; while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return 0; - } - len = MLEN; - } if (totlen >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - m_freem(top); - return 0; - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } - if (!top) { - register int pad = - ALIGN(sizeof(struct ether_header)) - - sizeof(struct ether_header); - m->m_data += pad; - len -= pad; + + if (m == m0) { + caddr_t newdata = (caddr_t) + ALIGN(m->m_data + sizeof(struct ether_header)) - + sizeof(struct ether_header); + len -= newdata - m->m_data; + m->m_data = newdata; } + m->m_len = len = min(totlen, len); (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len); boff += len; + totlen -= len; - *mp = m; - mp = &m->m_next; + if (totlen > 0) { + MGET(newm, M_DONTWAIT, MT_DATA); + if (newm == 0) + goto bad; + len = MLEN; + m = m->m_next = newm; + } } - return (top); + return (m0); + +bad: + m_freem(m0); + return (0); } /* diff --git a/sys/dev/isa/if_eg.c b/sys/dev/isa/if_eg.c index f08c8ef9daed..a499013763c7 100644 --- a/sys/dev/isa/if_eg.c +++ b/sys/dev/isa/if_eg.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_eg.c,v 1.43 1998/07/05 06:49:13 jonathan Exp $ */ +/* $NetBSD: if_eg.c,v 1.44 1998/12/12 16:58:11 mycroft Exp $ */ /* * Copyright (c) 1993 Dean Huxley @@ -816,45 +816,44 @@ egget(sc, buf, totlen) int totlen; { struct ifnet *ifp = &sc->sc_ethercom.ec_if; - struct mbuf *top, **mp, *m; + struct mbuf *m, *m0, *newm; int len; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return 0; - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) + return (0); + m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.len = totlen; len = MHLEN; - top = 0; - mp = ⊤ + m = m0; while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return 0; - } - len = MLEN; - } if (totlen >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - m_freem(top); - return 0; - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } + m->m_len = len = min(totlen, len); bcopy((caddr_t)buf, mtod(m, caddr_t), len); buf += len; + totlen -= len; - *mp = m; - mp = &m->m_next; + if (totlen > 0) { + MGET(newm, M_DONTWAIT, MT_DATA); + if (newm == 0) + goto bad; + len = MLEN; + m = m->m_next = newm; + } } - return top; + return (m0); + +bad: + m_freem(m0); + return (0); } int diff --git a/sys/dev/isa/if_el.c b/sys/dev/isa/if_el.c index 001a1ae6c0b8..7edc06321f82 100644 --- a/sys/dev/isa/if_el.c +++ b/sys/dev/isa/if_el.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_el.c,v 1.54 1998/07/05 06:49:13 jonathan Exp $ */ +/* $NetBSD: if_el.c,v 1.55 1998/12/12 16:58:11 mycroft Exp $ */ /* * Copyright (c) 1994, Matthew E. Kimmel. Permission is hereby granted @@ -643,50 +643,49 @@ elget(sc, totlen) struct ifnet *ifp = &sc->sc_ethercom.ec_if; bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; - struct mbuf *top, **mp, *m; + struct mbuf *m, *m0, *newm; int len; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return 0; - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) + return (0); + m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.len = totlen; len = MHLEN; - top = 0; - mp = ⊤ + m = m0; bus_space_write_1(iot, ioh, EL_GPBL, 0); bus_space_write_1(iot, ioh, EL_GPBH, 0); while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return 0; - } - len = MLEN; - } if (totlen >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - m_freem(top); - return 0; - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } + m->m_len = len = min(totlen, len); bus_space_read_multi_1(iot, ioh, EL_BUF, mtod(m, u_int8_t *), len); + totlen -= len; - *mp = m; - mp = &m->m_next; + if (totlen > 0) { + MGET(newm, M_DONTWAIT, MT_DATA); + if (newm == 0) + goto bad; + len = MLEN; + m = m->m_next = newm; + } } bus_space_write_1(iot, ioh, EL_RBC, 0); bus_space_write_1(iot, ioh, EL_AC, EL_AC_RX); - return top; + return (m0); + +bad: + m_freem(m0); + return (0); } /* diff --git a/sys/dev/scsipi/if_se.c b/sys/dev/scsipi/if_se.c index 2bc53a672663..c6488f81d16a 100644 --- a/sys/dev/scsipi/if_se.c +++ b/sys/dev/scsipi/if_se.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_se.c,v 1.22 1998/12/08 00:19:27 thorpej Exp $ */ +/* $NetBSD: if_se.c,v 1.23 1998/12/12 17:08:14 mycroft Exp $ */ /* * Copyright (c) 1997 Ian W. Dall @@ -582,49 +582,53 @@ se_get(sc, data, totlen) char *data; int totlen; { - struct mbuf *m; - struct mbuf *top, **mp; struct ifnet *ifp = &sc->sc_ethercom.ec_if; - int len, pad; + struct mbuf *m, *m0, *newm; + int len; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) return (0); - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; - pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header); - m->m_data += pad; - len = MHLEN - pad; - top = 0; - mp = ⊤ + m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.len = totlen; + len = MHLEN; + m = m0; while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return (0); - } - len = MLEN; - } if (totlen >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - m_freem(top); - return (0); - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } + + if (m == m0) { + caddr_t newdata = (caddr_t) + ALIGN(m->m_data + sizeof(struct ether_header)) - + sizeof(struct ether_header); + len -= newdata - m->m_data; + m->m_data = newdata; + } + m->m_len = len = min(totlen, len); bcopy(data, mtod(m, caddr_t), len); data += len; + totlen -= len; - *mp = m; - mp = &m->m_next; + if (totlen > 0) { + MGET(newm, M_DONTWAIT, MT_DATA); + if (newm == 0) + goto bad; + len = MLEN; + m = m->m_next = newm; + } } - return (top); + return (m0); + +bad: + m_freem(m0); + return (0); } /*