Plug memory leak in jumbo buffer allocation failure path.

Patch in the PR was modified to check active jumbo buffers in use
and other possible jumbo buffer leak.

Jumbo buffer usage in lge(4) still wouldn't be reliable due to lack
of driver lock in local jumbo buffer allocator. Either introduce
a new lock to protect jumbo buffer or switch to UMA backed page
allocator for jumbo frame is required.

PR:	kern/78072
This commit is contained in:
Pyun YongHyeon 2008-03-05 05:36:09 +00:00
parent 7be5912e3f
commit eeeebe75aa

View File

@ -535,7 +535,6 @@ lge_attach(dev)
ifp = sc->lge_ifp = if_alloc(IFT_ETHER);
if (ifp == NULL) {
device_printf(dev, "can not if_alloc()\n");
lge_free_jumbo_mem(sc);
error = ENOSPC;
goto fail;
}
@ -562,7 +561,6 @@ lge_attach(dev)
if (mii_phy_probe(dev, &sc->lge_miibus,
lge_ifmedia_upd, lge_ifmedia_sts)) {
device_printf(dev, "MII without any PHY!\n");
lge_free_jumbo_mem(sc);
error = ENXIO;
goto fail;
}
@ -583,6 +581,7 @@ lge_attach(dev)
return (0);
fail:
lge_free_jumbo_mem(sc);
if (sc->lge_ldata)
contigfree(sc->lge_ldata,
sizeof(struct lge_list_data), M_DEVBUF);
@ -804,10 +803,19 @@ static void
lge_free_jumbo_mem(sc)
struct lge_softc *sc;
{
int i;
struct lge_jpool_entry *entry;
for (i = 0; i < LGE_JSLOTS; i++) {
if (sc->lge_cdata.lge_jumbo_buf == NULL)
return;
while ((entry = SLIST_FIRST(&sc->lge_jinuse_listhead))) {
device_printf(sc->lge_dev,
"asked to free buffer that is in use!\n");
SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries);
SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry,
jpool_entries);
}
while (!SLIST_EMPTY(&sc->lge_jfree_listhead)) {
entry = SLIST_FIRST(&sc->lge_jfree_listhead);
SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries);
free(entry, M_DEVBUF);