Date: Mon, 19 Feb 2007 02:07:25 -0800 From: Luigi Rizzo <rizzo@icir.org> To: current@freebsd.org Subject: can a valid bus_dma_tag_t be NULL ? Message-ID: <20070219020725.A56400@xorpc.icir.org>
next in thread | raw e-mail | index | archive | help
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: ... ---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070219020725.A56400>