diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2006-10-03 20:06:22 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2006-10-03 20:06:22 +0000 |
commit | 823b5f8c17155bc417b2b9f72b95fcab94a46475 (patch) | |
tree | 27a73d4c1342749845b84b868ceb64aa81c590b7 /sys | |
parent | 780868e0f51f05f749bd9cb95020b548a1aa925b (diff) |
Simplify the code dealing with the mbuf chain in dp8390_get().
From bad@ & mycroft@ NetBSD
Tested by nick@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ic/dp8390.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/sys/dev/ic/dp8390.c b/sys/dev/ic/dp8390.c index 7277211190b..87bc051ffae 100644 --- a/sys/dev/ic/dp8390.c +++ b/sys/dev/ic/dp8390.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dp8390.c,v 1.32 2006/09/17 18:03:06 brad Exp $ */ +/* $OpenBSD: dp8390.c,v 1.33 2006/10/03 20:06:21 brad Exp $ */ /* $NetBSD: dp8390.c,v 1.13 1998/07/05 06:49:11 jonathan Exp $ */ /* @@ -155,7 +155,7 @@ dp8390_mediachange(ifp) if (sc->sc_mediachange) return ((*sc->sc_mediachange)(sc)); - return (EINVAL); + return (0); } /* @@ -1016,41 +1016,29 @@ dp8390_get(sc, src, total_len) u_short total_len; { struct ifnet *ifp = &sc->sc_arpcom.ac_if; - struct mbuf *top, **mp, *m; + struct mbuf *m, *m0, *newm; u_short len; - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return 0; - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = total_len; + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 == 0) + return (0); + m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.len = total_len; len = MHLEN; - top = 0; - mp = ⊤ + m = m0; while (total_len > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return 0; - } - len = MLEN; - } if (total_len >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_freem(m); - m_freem(top); - return 0; - } + if ((m->m_flags & M_EXT) == 0) + goto bad; len = MCLBYTES; } /* * Make sure the data after the Ethernet header is aligned. */ - if (top == NULL) { + if (m == m0) { caddr_t newdata = (caddr_t) ALIGN(m->m_data + sizeof(struct ether_header)) - sizeof(struct ether_header); @@ -1063,12 +1051,22 @@ dp8390_get(sc, src, total_len) src = (*sc->ring_copy)(sc, src, mtod(m, caddr_t), len); else src = dp8390_ring_copy(sc, src, mtod(m, caddr_t), len); + total_len -= len; - *mp = m; - mp = &m->m_next; + if (total_len > 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); } |