Module Name: src Committed By: macallan Date: Fri Jun 12 17:24:02 UTC 2015
Modified Files: src/sys/dev/ic: dm9000.c Log Message: actually check the return value from m_gethdr() and deal with errors now we no longer segfault in dme_allocate_buffer() To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/dm9000.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/dm9000.c diff -u src/sys/dev/ic/dm9000.c:1.7 src/sys/dev/ic/dm9000.c:1.8 --- src/sys/dev/ic/dm9000.c:1.7 Sat Mar 14 13:45:43 2015 +++ src/sys/dev/ic/dm9000.c Fri Jun 12 17:24:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dm9000.c,v 1.7 2015/03/14 13:45:43 macallan Exp $ */ +/* $NetBSD: dm9000.c,v 1.8 2015/06/12 17:24:02 macallan Exp $ */ /* * Copyright (c) 2009 Paul Fleischer @@ -809,8 +809,12 @@ dme_receive(struct dme_softc *sc, struct sc->dme_io, DM9000_MRCMD); rx_status = sc->sc_pkt_read(sc, ifp, &m); - - if (rx_status & (DM9000_RSR_CE | DM9000_RSR_PLE)) { + if (m == NULL) { + /* failed to allocate a receive buffer */ + ifp->if_ierrors++; + RX_DPRINTF(("dme_receive: " + "Error allocating buffer\n")); + } else if (rx_status & (DM9000_RSR_CE | DM9000_RSR_PLE)) { /* Error while receiving the packet, * discard it and keep track of counters */ @@ -1082,6 +1086,18 @@ dme_pkt_read_2(struct dme_softc *sc, str m = dme_alloc_receive_buffer(ifp, frame_length); + if (m == NULL) { + /* + * didn't get a receive buffer, so we read the rest of the + * packet, throw it away and return an error + */ + for (i = 0; i < frame_length; i += 2 ) { + data = bus_space_read_2(sc->sc_iot, + sc->sc_ioh, sc->dme_data); + } + *outBuf = NULL; + return 0; + } buf = mtod(m, uint16_t*); @@ -1163,6 +1179,18 @@ dme_pkt_read_1(struct dme_softc *sc, str m = dme_alloc_receive_buffer(ifp, frame_length); + if (m == NULL) { + /* + * didn't get a receive buffer, so we read the rest of the + * packet, throw it away and return an error + */ + for (i = 0; i < frame_length; i++ ) { + data = bus_space_read_2(sc->sc_iot, + sc->sc_ioh, sc->dme_data); + } + *outBuf = NULL; + return 0; + } buf = mtod(m, uint8_t *); @@ -1190,6 +1218,8 @@ dme_alloc_receive_buffer(struct ifnet *i int pad; MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == NULL) return NULL; + m->m_pkthdr.rcvif = ifp; /* Ensure that we always allocate an even number of * bytes in order to avoid writing beyond the buffer