Module Name:    src
Committed By:   nat
Date:           Tue May 23 07:57:26 UTC 2017

Modified Files:
        src/sys/dev: audio.c

Log Message:
Fix broken logic with regard to the use of uvm_unmap.  Call uvm_unmap with
the correct arguments.

Ok chs@.


To generate a diff of this commit:
cvs rdiff -u -r1.351 -r1.352 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.351 src/sys/dev/audio.c:1.352
--- src/sys/dev/audio.c:1.351	Tue May 16 23:55:53 2017
+++ src/sys/dev/audio.c	Tue May 23 07:57:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.351 2017/05/16 23:55:53 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.352 2017/05/23 07:57:26 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.351 2017/05/16 23:55:53 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.352 2017/05/23 07:57:26 nat Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -1191,9 +1191,8 @@ audio_alloc_ring(struct audio_softc *sc,
 	if (bufsize < AUMINBUF)
 		bufsize = AUMINBUF;
 	ROUNDSIZE(bufsize);
-	if (hw->round_buffersize) {
+	if (hw->round_buffersize)
 		bufsize = hw->round_buffersize(hdl, direction, bufsize);
-	}
 
 	if (hw->allocm && (r == &chan->vc->sc_mpr || r == &chan->vc->sc_mrr)) {
 		/* Hardware ringbuffer.	 No dedicated uvm object.*/
@@ -1215,16 +1214,16 @@ audio_alloc_ring(struct audio_softc *sc,
 		error = uvm_map(kernel_map, &vstart, vsize, r->uobj, 0, 0,
 		    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_NONE,
 			UVM_ADV_RANDOM, 0));
-		if (error)
-			goto bad_map;
+		if (error) {
+			uao_detach(r->uobj);	/* release reference */
+			r->uobj = NULL;		/* paranoia */
+			return error;
+		}
 
 		error = uvm_map_pageable(kernel_map, vstart, vstart + vsize,
 		    false, 0);
-
 		if (error) {
-			uvm_unmap(kernel_map, vstart, vsize);
-bad_map:
-			uao_detach(r->uobj);	/* release reference */
+			uvm_unmap(kernel_map, vstart, vstart + vsize);
 			r->uobj = NULL;		/* paranoia */
 			return error;
 		}
@@ -1254,14 +1253,18 @@ audio_free_ring(struct audio_softc *sc, 
 		KASSERT(r->uobj == NULL);
 		sc->hw_if->freem(sc->hw_hdl, r->s.start, r->s.bufsize);
 	} else {
-				/* Software ringbuffer.	 */
+		/* Software ringbuffer.  */
 		vstart = (vaddr_t)r->s.start;
 		vsize = roundup2(MAX(r->s.bufsize, PAGE_SIZE), PAGE_SIZE);
 
-		uvm_map_pageable(kernel_map, vstart, vstart + vsize,
-		    true, 0);
-		uvm_unmap(kernel_map, vstart, vsize);
-		uao_detach(r->uobj);	/* release reference */
+		/*
+		 * Unmap the kernel mapping.  uvm_unmap releases the
+		 * reference to the uvm object, and this should be the
+		 * last virtual mapping of the uvm object, so no need
+		 * to explicitly release (`detach') the object.
+		 */
+		uvm_unmap(kernel_map, vstart, vstart + vsize);
+
 		r->uobj = NULL;		/* paranoia */
 	}
 

Reply via email to