https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288309

            Bug ID: 288309
           Summary: genet driver memory leak in dma teardown (cut and
                    paste issue)
           Product: Base System
           Version: 13.5-STABLE
          Hardware: arm64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: [email protected]
          Reporter: [email protected]

There is a memory leak in an error path where gen_bus_dma_teardown is called.
The tx_buf_tag is checked in both cases instead of checking the rx_buf_tag in
the second case where rx dma mappings are destroyed.

i.e.
        if (sc->tx_buf_tag != NULL) {
                for (i = 0; i < RX_DESC_COUNT; i++) {
should be
        if (sc->rx_buf_tag != NULL) {
                for (i = 0; i < RX_DESC_COUNT; i++) {

Since this is an error path, this is not a big issue.  However we have added a
detach handler that is leveraging this function.  Please consider adding a
detach handler.
e.g.
static int
gen_detach(device_t dev)
{
        struct gen_softc *sc;

        sc = device_get_softc(dev);

        GEN_LOCK(sc);
        gen_stop(sc);
        GEN_UNLOCK(sc);
        callout_drain(&sc->stat_ch);
        ether_ifdetach(sc->ifp);

        /* Detach the miibus */
        if (sc->miibus) {
                device_delete_child(dev, sc->miibus);
        }
        bus_generic_detach(dev);

        if (sc->ifp != NULL) {
                if_free(sc->ifp);
        }

        /* clean up dma */
        gen_bus_dma_teardown(sc);

        /* Release bus resources. */
        if (sc->ih != NULL) {
                bus_teardown_intr(sc->dev, sc->res[_RES_IRQ1], sc->ih);
        }
        if (sc->ih2 != NULL) {
                bus_teardown_intr(sc->dev, sc->res[_RES_IRQ2], sc->ih2);
        }
        bus_release_resources(sc->dev, gen_spec, sc->res);

        mtx_destroy(&sc->mtx);
        return 0;
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to