diff options
author | wpaul <wpaul@FreeBSD.org> | 2001-06-18 22:04:40 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 2001-06-18 22:04:40 +0000 |
commit | 00f007fadec7782a3312eed13872c7aff0fe8afe (patch) | |
tree | 9b2a9deed908d3402c0e933be7e111ac10eef6ca | |
parent | ce724d80ee3964d73ffcc96448b062a8030c480a (diff) | |
download | FreeBSD-src-00f007fadec7782a3312eed13872c7aff0fe8afe.zip FreeBSD-src-00f007fadec7782a3312eed13872c7aff0fe8afe.tar.gz |
Fix some memory bugs with regard to jumbo buffers. I made a mistake when
converting from the old external mbuf buffer code to the new (with the
MEXTADD() macro). Also free free list memory correctly in
foo_free_jumbo_mem() routines: grab the head of the list, then
remove it, _then_ free() it.
This fixes the memory corruption problem I've been chasing in the level 1
driver.
-rw-r--r-- | sys/dev/lge/if_lge.c | 12 | ||||
-rw-r--r-- | sys/dev/lge/if_lgereg.h | 1 | ||||
-rw-r--r-- | sys/dev/nge/if_nge.c | 12 | ||||
-rw-r--r-- | sys/dev/nge/if_ngereg.h | 1 |
4 files changed, 10 insertions, 16 deletions
diff --git a/sys/dev/lge/if_lge.c b/sys/dev/lge/if_lge.c index ea91f9b..d6f9e80 100644 --- a/sys/dev/lge/if_lge.c +++ b/sys/dev/lge/if_lge.c @@ -791,12 +791,12 @@ static int lge_newbuf(sc, c, m) } /* Attach the buffer to the mbuf */ m_new->m_data = (void *)buf; - m_new->m_len = m_new->m_pkthdr.len = LGE_MCLBYTES; - MEXTADD(m_new, buf, LGE_MCLBYTES, lge_jfree, + m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN; + MEXTADD(m_new, buf, LGE_JUMBO_FRAMELEN, lge_jfree, (struct lge_softc *)sc, 0, EXT_NET_DRV); } else { m_new = m; - m_new->m_len = m_new->m_pkthdr.len = LGE_MCLBYTES; + m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN; m_new->m_data = m_new->m_ext.ext_buf; } @@ -857,12 +857,10 @@ static int lge_alloc_jumbo_mem(sc) ptr = sc->lge_cdata.lge_jumbo_buf; for (i = 0; i < LGE_JSLOTS; i++) { sc->lge_cdata.lge_jslots[i] = ptr; - ptr += LGE_MCLBYTES; + ptr += LGE_JLEN; entry = malloc(sizeof(struct lge_jpool_entry), M_DEVBUF, M_NOWAIT); if (entry == NULL) { - free(sc->lge_cdata.lge_jumbo_buf, M_DEVBUF); - sc->lge_cdata.lge_jumbo_buf = NULL; printf("lge%d: no memory for jumbo " "buffer queue!\n", sc->lge_unit); return(ENOBUFS); @@ -883,8 +881,8 @@ static void lge_free_jumbo_mem(sc) for (i = 0; i < LGE_JSLOTS; i++) { entry = SLIST_FIRST(&sc->lge_jfree_listhead); - free(entry, M_DEVBUF); SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries); + free(entry, M_DEVBUF); } contigfree(sc->lge_cdata.lge_jumbo_buf, LGE_JMEM, M_DEVBUF); diff --git a/sys/dev/lge/if_lgereg.h b/sys/dev/lge/if_lgereg.h index 7815675..f0254b1 100644 --- a/sys/dev/lge/if_lgereg.h +++ b/sys/dev/lge/if_lgereg.h @@ -502,7 +502,6 @@ struct lge_mii_frame { #define LGE_JRAWLEN (LGE_JUMBO_FRAMELEN + ETHER_ALIGN) #define LGE_JLEN (LGE_JRAWLEN + (sizeof(u_int64_t) - \ (LGE_JRAWLEN % sizeof(u_int64_t)))) -#define LGE_MCLBYTES (LGE_JLEN - sizeof(u_int64_t)) #define LGE_JPAGESZ PAGE_SIZE #define LGE_RESID (LGE_JPAGESZ - (LGE_JLEN * LGE_JSLOTS) % LGE_JPAGESZ) #define LGE_JMEM ((LGE_JLEN * LGE_JSLOTS) + LGE_RESID) diff --git a/sys/dev/nge/if_nge.c b/sys/dev/nge/if_nge.c index ed74087..9c15beb 100644 --- a/sys/dev/nge/if_nge.c +++ b/sys/dev/nge/if_nge.c @@ -1098,12 +1098,12 @@ static int nge_newbuf(sc, c, m) } /* Attach the buffer to the mbuf */ m_new->m_data = (void *)buf; - m_new->m_len = m_new->m_pkthdr.len = NGE_MCLBYTES; - MEXTADD(m_new, buf, NGE_MCLBYTES, nge_jfree, + m_new->m_len = m_new->m_pkthdr.len = NGE_JUMBO_FRAMELEN; + MEXTADD(m_new, buf, NGE_JUMBO_FRAMELEN, nge_jfree, (struct nge_softc *)sc, 0, EXT_NET_DRV); } else { m_new = m; - m_new->m_len = m_new->m_pkthdr.len = NGE_MCLBYTES; + m_new->m_len = m_new->m_pkthdr.len = NGE_JUMBO_FRAMELEN; m_new->m_data = m_new->m_ext.ext_buf; } @@ -1143,12 +1143,10 @@ static int nge_alloc_jumbo_mem(sc) ptr = sc->nge_cdata.nge_jumbo_buf; for (i = 0; i < NGE_JSLOTS; i++) { sc->nge_cdata.nge_jslots[i] = ptr; - ptr += NGE_MCLBYTES; + ptr += NGE_JLEN; entry = malloc(sizeof(struct nge_jpool_entry), M_DEVBUF, M_NOWAIT); if (entry == NULL) { - free(sc->nge_cdata.nge_jumbo_buf, M_DEVBUF); - sc->nge_cdata.nge_jumbo_buf = NULL; printf("nge%d: no memory for jumbo " "buffer queue!\n", sc->nge_unit); return(ENOBUFS); @@ -1169,8 +1167,8 @@ static void nge_free_jumbo_mem(sc) for (i = 0; i < NGE_JSLOTS; i++) { entry = SLIST_FIRST(&sc->nge_jfree_listhead); - free(entry, M_DEVBUF); SLIST_REMOVE_HEAD(&sc->nge_jfree_listhead, jpool_entries); + free(entry, M_DEVBUF); } contigfree(sc->nge_cdata.nge_jumbo_buf, NGE_JMEM, M_DEVBUF); diff --git a/sys/dev/nge/if_ngereg.h b/sys/dev/nge/if_ngereg.h index 56c141c..575ae2fe 100644 --- a/sys/dev/nge/if_ngereg.h +++ b/sys/dev/nge/if_ngereg.h @@ -611,7 +611,6 @@ struct nge_mii_frame { #define NGE_JRAWLEN (NGE_JUMBO_FRAMELEN + ETHER_ALIGN) #define NGE_JLEN (NGE_JRAWLEN + (sizeof(u_int64_t) - \ (NGE_JRAWLEN % sizeof(u_int64_t)))) -#define NGE_MCLBYTES (NGE_JLEN - sizeof(u_int64_t)) #define NGE_JPAGESZ PAGE_SIZE #define NGE_RESID (NGE_JPAGESZ - (NGE_JLEN * NGE_JSLOTS) % NGE_JPAGESZ) #define NGE_JMEM ((NGE_JLEN * NGE_JSLOTS) + NGE_RESID) |