can a valid bus_dma_tag_t be NULL ?

From: Luigi Rizzo <rizzo_at_icir.org>
Date: Mon, 19 Feb 2007 02:07:25 -0800
I am trying to cleanup some code that allocates dma-able
regions and has to release it in case some of the step
goes wrong.

The original code (if_iwi.c, but the pattern is repeated in other
drivers too) is the one below. Now, rather than using multiple
labels, is there a value for the various fields (bus_dma_tag_t,
bus_dmamap_t, fw_virtaddr, fw_physaddr) that tells me
that the resource has not been allocated, or i should keep
track of the success/failure of the various calls separately ?

E.g. i imagine that a NULL fw_virtaddr means failure, however
bus_dmamap_load() worries me because the callback may happen later,
and also i seem to remember that one should not make assumptions
on bus_dma_tag_t == NULL ... 

comments anyone ? And, is -stable different from -current ?
cheers
luigi


        if (bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
            BUS_SPACE_MAXADDR, NULL, NULL, sc->fw_dma_size, 1, sc->fw_dma_size,
            0, NULL, NULL, &sc->fw_dmat) != 0) {
                device_printf(sc->sc_dev,
                    "could not create firmware DMA tag\n");
                IWI_LOCK(sc);
                goto fail;
        }
        if (bus_dmamem_alloc(sc->fw_dmat, &sc->fw_virtaddr, 0,
            &sc->fw_map) != 0) {
                device_printf(sc->sc_dev,
                    "could not allocate firmware DMA memory\n");
                IWI_LOCK(sc);
                goto fail2;
        }
        if (bus_dmamap_load(sc->fw_dmat, sc->fw_map, sc->fw_virtaddr,
            sc->fw_dma_size, iwi_dma_map_addr, &sc->fw_physaddr, 0) != 0) {
                device_printf(sc->sc_dev, "could not load firmware DMA map\n");
                IWI_LOCK(sc);
                goto fail3;
        }

	... use the memory ...

        bus_dmamap_unload(sc->fw_dmat, sc->fw_map);
fail3:  bus_dmamem_free(sc->fw_dmat, sc->fw_virtaddr, sc->fw_map);
fail2:  bus_dma_tag_destroy(sc->fw_dmat);
fail:	...

---
Received on Mon Feb 19 2007 - 09:07:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:05 UTC