Date: Tue, 24 Feb 2015 06:08:56 +0000 (UTC) From: Andrew Rybchenko <arybchik@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279230 - head/sys/dev/sfxge Message-ID: <201502240608.t1O68uxG003031@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: arybchik Date: Tue Feb 24 06:08:55 2015 New Revision: 279230 URL: https://svnweb.freebsd.org/changeset/base/279230 Log: sfxge: use goto to cleanup to avoid duplicate cleanup code Sponsored by: Solarflare Communications, Inc. Approved by: gnn (mentor) Modified: head/sys/dev/sfxge/sfxge_dma.c Modified: head/sys/dev/sfxge/sfxge_dma.c ============================================================================== --- head/sys/dev/sfxge/sfxge_dma.c Tue Feb 24 05:43:16 2015 (r279229) +++ head/sys/dev/sfxge/sfxge_dma.c Tue Feb 24 06:08:55 2015 (r279230) @@ -141,7 +141,7 @@ sfxge_dma_alloc(struct sfxge_softc *sc, MIN(0x3FFFFFFFFFFFUL, BUS_SPACE_MAXADDR), BUS_SPACE_MAXADDR, NULL, NULL, len, 1, len, 0, NULL, NULL, &esmp->esm_tag) != 0) { device_printf(sc->dev, "Couldn't allocate txq DMA tag\n"); - return (ENOMEM); + goto fail_tag_create; } /* Allocate kernel memory. */ @@ -149,17 +149,14 @@ sfxge_dma_alloc(struct sfxge_softc *sc, BUS_DMA_WAITOK | BUS_DMA_COHERENT | BUS_DMA_ZERO, &esmp->esm_map) != 0) { device_printf(sc->dev, "Couldn't allocate DMA memory\n"); - bus_dma_tag_destroy(esmp->esm_tag); - return (ENOMEM); + goto fail_alloc; } /* Load map into device memory. */ if (bus_dmamap_load(esmp->esm_tag, esmp->esm_map, vaddr, len, sfxge_dma_cb, &esmp->esm_addr, 0) != 0) { device_printf(sc->dev, "Couldn't load DMA mapping\n"); - bus_dmamem_free(esmp->esm_tag, vaddr, esmp->esm_map); - bus_dma_tag_destroy(esmp->esm_tag); - return (ENOMEM); + goto fail_load; } /* @@ -167,15 +164,20 @@ sfxge_dma_alloc(struct sfxge_softc *sc, * and will have set esm_addr to 0 if something went * wrong. */ - if (esmp->esm_addr == 0) { - bus_dmamem_free(esmp->esm_tag, vaddr, esmp->esm_map); - bus_dma_tag_destroy(esmp->esm_tag); - return (ENOMEM); - } + if (esmp->esm_addr == 0) + goto fail_load_check; esmp->esm_base = vaddr; return (0); + +fail_load_check: +fail_load: + bus_dmamem_free(esmp->esm_tag, vaddr, esmp->esm_map); +fail_alloc: + bus_dma_tag_destroy(esmp->esm_tag); +fail_tag_create: + return (ENOMEM); } void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502240608.t1O68uxG003031>