Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Dec 2015 15:55:15 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r292778 - stable/9/sys/x86/x86
Message-ID:  <201512271555.tBRFtFu0001751@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Sun Dec 27 15:55:15 2015
New Revision: 292778
URL: https://svnweb.freebsd.org/changeset/base/292778

Log:
  MFC: r286785, r291088, r291120
  - Reformat x86 bounce buffer synchronization code to reduce indentation.
    No functional change.
  - Avoid a NULL pointer dereference in bounce_bus_dmamap_sync() when the
    map has been created via bounce_bus_dmamem_alloc(). Even for coherent
    DMA - which bus_dmamem_alloc(9) typically is used for -, calling of
    bus_dmamap_sync(9) isn't optional. [1]
  - Avoid a NULL pointer dereference in bounce_bus_dmamap_unload() when
    the map has been created via bounce_bus_dmamem_alloc(). In that case
    bus_dmamap_unload(9) typically isn't called during normal operation
    but still should be during detach, cleanup from failed attach etc. [2]
  
  PR:		188899 (non-original problem) [1]
  Submitted by:	yongari [2]

Modified:
  stable/9/sys/x86/x86/busdma_machdep.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/x86/x86/busdma_machdep.c
==============================================================================
--- stable/9/sys/x86/x86/busdma_machdep.c	Sun Dec 27 15:37:07 2015	(r292777)
+++ stable/9/sys/x86/x86/busdma_machdep.c	Sun Dec 27 15:55:15 2015	(r292778)
@@ -888,6 +888,9 @@ _bus_dmamap_unload(bus_dma_tag_t dmat, b
 {
 	struct bounce_page *bpage;
 
+	if (map == NULL)
+		return;
+
 	while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) {
 		STAILQ_REMOVE_HEAD(&map->bpages, links);
 		free_bounce_page(dmat, bpage);
@@ -899,44 +902,43 @@ _bus_dmamap_sync(bus_dma_tag_t dmat, bus
 {
 	struct bounce_page *bpage;
 
-	if ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) {
-		/*
-		 * Handle data bouncing.  We might also
-		 * want to add support for invalidating
-		 * the caches on broken hardware
-		 */
-		CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x op 0x%x "
-		    "performing bounce", __func__, op, dmat, dmat->flags);
+	if (map == NULL || (bpage = STAILQ_FIRST(&map->bpages)) == NULL)
+		return;
 
-		if (op & BUS_DMASYNC_PREWRITE) {
-			while (bpage != NULL) {
-				if (bpage->datavaddr != 0)
-					bcopy((void *)bpage->datavaddr,
-					      (void *)bpage->vaddr,
-					      bpage->datacount);
-				else
-					physcopyout(bpage->dataaddr,
-					      (void *)bpage->vaddr,
-					      bpage->datacount);
-				bpage = STAILQ_NEXT(bpage, links);
+	/*
+	 * Handle data bouncing.  We might also want to add support for
+	 * invalidating the caches on broken hardware.
+	 */
+	CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x op 0x%x "
+	    "performing bounce", __func__, op, dmat, dmat->flags);
+
+	if ((op & BUS_DMASYNC_PREWRITE) != 0) {
+		while (bpage != NULL) {
+			if (bpage->datavaddr != 0) {
+				bcopy((void *)bpage->datavaddr,
+				    (void *)bpage->vaddr, bpage->datacount);
+			} else {
+				physcopyout(bpage->dataaddr,
+				    (void *)bpage->vaddr, bpage->datacount);
 			}
-			dmat->bounce_zone->total_bounced++;
+			bpage = STAILQ_NEXT(bpage, links);
 		}
+		dmat->bounce_zone->total_bounced++;
+	}
 
-		if (op & BUS_DMASYNC_POSTREAD) {
-			while (bpage != NULL) {
-				if (bpage->datavaddr != 0)
-					bcopy((void *)bpage->vaddr,
-					      (void *)bpage->datavaddr,
-					      bpage->datacount);
-				else
-					physcopyin((void *)bpage->vaddr,
-					      bpage->dataaddr,
-					      bpage->datacount);
-				bpage = STAILQ_NEXT(bpage, links);
+	if ((op & BUS_DMASYNC_POSTREAD) != 0) {
+		while (bpage != NULL) {
+			if (bpage->datavaddr != 0) {
+				bcopy((void *)bpage->vaddr,
+				    (void *)bpage->datavaddr,
+				    bpage->datacount);
+			} else {
+				physcopyin((void *)bpage->vaddr,
+				    bpage->dataaddr, bpage->datacount);
 			}
-			dmat->bounce_zone->total_bounced++;
+			bpage = STAILQ_NEXT(bpage, links);
 		}
+		dmat->bounce_zone->total_bounced++;
 	}
 }
 
@@ -955,12 +957,14 @@ SYSINIT(bpages, SI_SUB_LOCK, SI_ORDER_AN
 static struct sysctl_ctx_list *
 busdma_sysctl_tree(struct bounce_zone *bz)
 {
+
 	return (&bz->sysctl_tree);
 }
 
 static struct sysctl_oid *
 busdma_sysctl_tree_top(struct bounce_zone *bz)
 {
+
 	return (bz->sysctl_tree_top);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512271555.tBRFtFu0001751>