svn commit: r280590 - stable/10/sys/dev/sfxge

Andrew Rybchenko arybchik at FreeBSD.org
Wed Mar 25 13:13:34 UTC 2015


Author: arybchik
Date: Wed Mar 25 13:13:32 2015
New Revision: 280590
URL: https://svnweb.freebsd.org/changeset/base/280590

Log:
  MFC: 279230
  
  sfxge: use goto to cleanup to avoid duplicate cleanup code
  
  Sponsored by:   Solarflare Communications, Inc.
  Approved by:    gnn (mentor)

Modified:
  stable/10/sys/dev/sfxge/sfxge_dma.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/sfxge/sfxge_dma.c
==============================================================================
--- stable/10/sys/dev/sfxge/sfxge_dma.c	Wed Mar 25 13:12:15 2015	(r280589)
+++ stable/10/sys/dev/sfxge/sfxge_dma.c	Wed Mar 25 13:13:32 2015	(r280590)
@@ -137,7 +137,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. */
@@ -145,17 +145,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;
 	}
 
 	/*
@@ -163,15 +160,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


More information about the svn-src-all mailing list