Module Name:    src
Committed By:   martin
Date:           Sun Feb 28 07:05:14 UTC 2021

Modified Files:
        src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1217):

        sys/dev/audio/audio.c: revision 1.46
        sys/dev/audio/audio.c: revision 1.82
        sys/dev/audio/audio.c: revision 1.85
        sys/dev/audio/audio.c: revision 1.87
        sys/dev/audio/audio.c: revision 1.88

Change two aprint_error_dev() to device_printf() (and improve messages).
This is also called from other than boot.

Add missing newline.

Revise comments.

Change (harmless) zero-length debug messages.
sys/modules is compiled with -Wzero-length-format and this
makes sys/modules compilable even if AUDIO_DEBUG is defined.

Improve error messages.
- prefix MD device name if it's considered to be related to the MD driver.
- revise some messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.18 -r1.28.2.19 src/sys/dev/audio/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/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.18 src/sys/dev/audio/audio.c:1.28.2.19
--- src/sys/dev/audio/audio.c:1.28.2.18	Sat Dec 19 13:54:56 2020
+++ src/sys/dev/audio/audio.c	Sun Feb 28 07:05:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -518,6 +518,8 @@ static void audio_mixer_restore(struct a
 static void audio_softintr_rd(void *);
 static void audio_softintr_wr(void *);
 
+static void audio_printf(struct audio_softc *, const char *, ...)
+	__printflike(2, 3);
 static int audio_exlock_mutex_enter(struct audio_softc *);
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
@@ -965,19 +967,20 @@ audioattach(device_t parent, device_t se
 		perror = audio_hw_probe(sc, &phwfmt, AUMODE_PLAY);
 		rerror = audio_hw_probe(sc, &rhwfmt, AUMODE_RECORD);
 		if (perror && rerror) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			    "perror = %d, rerror = %d\n", perror, rerror);
+			aprint_error_dev(self,
+			    "audio_hw_probe failed: perror=%d, rerror=%d\n",
+			    perror, rerror);
 			goto bad;
 		}
 		if (perror) {
 			mode &= ~AUMODE_PLAY;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			    "%d, playback disabled\n", perror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			    "errno=%d, playback disabled\n", perror);
 		}
 		if (rerror) {
 			mode &= ~AUMODE_RECORD;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			    "%d, capture disabled\n", rerror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			    "errno=%d, capture disabled\n", rerror);
 		}
 	} else {
 		/*
@@ -987,8 +990,8 @@ audioattach(device_t parent, device_t se
 		audio_format2_t *fmt = has_playback ? &phwfmt : &rhwfmt;
 		error = audio_hw_probe(sc, fmt, mode);
 		if (error) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			    "error = %d\n", error);
+			aprint_error_dev(self,
+			    "audio_hw_probe failed: errno=%d\n", error);
 			goto bad;
 		}
 		if (has_playback && has_capture)
@@ -999,8 +1002,8 @@ audioattach(device_t parent, device_t se
 	/* hw_probe() also validates [pr]hwfmt.  */
 	error = audio_hw_set_format(sc, mode, &phwfmt, &rhwfmt, &pfil, &rfil);
 	if (error) {
-		aprint_error_dev(self, "audio_hw_set_format failed, "
-		    "error = %d\n", error);
+		aprint_error_dev(self,
+		    "audio_hw_set_format failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1010,8 +1013,8 @@ audioattach(device_t parent, device_t se
 	 */
 	error = audio_mixers_init(sc, mode, &phwfmt, &rhwfmt, &pfil, &rfil);
 	if (sc->sc_pmixer == NULL && sc->sc_rmixer == NULL) {
-		aprint_error_dev(self, "audio_mixers_init failed, "
-		    "error = %d\n", error);
+		aprint_error_dev(self,
+		    "audio_mixers_init failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1429,6 +1432,22 @@ audio_attach_mi(const struct audio_hw_if
 }
 
 /*
+ * audio_printf() outputs fmt... with the audio device name and MD device
+ * name prefixed.  If the message is considered to be related to the MD
+ * driver, use this one instead of device_printf().
+ */
+static void
+audio_printf(struct audio_softc *sc, const char *fmt, ...)
+{
+	va_list ap;
+
+	printf("%s(%s): ", device_xname(sc->sc_dev), device_xname(sc->hw_dev));
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+}
+
+/*
  * Enter critical section and also keep sc_lock.
  * If successful, returns 0 with sc_lock held.  Otherwise returns errno.
  * Must be called without sc_lock held.
@@ -1574,7 +1593,7 @@ audio_track_waitio(struct audio_softc *s
 	if (error) {
 		TRACET(2, track, "cv_timedwait_sig failed %d", error);
 		if (error == EWOULDBLOCK)
-			device_printf(sc->sc_dev, "device timeout\n");
+			audio_printf(sc, "device timeout\n");
 	} else {
 		TRACET(3, track, "wakeup");
 	}
@@ -2408,7 +2427,8 @@ audio_unlink(struct audio_softc *sc, aud
 
 	/*
 	 * Acquire exlock to protect counters.
-	 * Does not use audio_exlock_enter() due to sc_dying.
+	 * audio_exlock_enter() cannot be used here because we have to go
+	 * forward even if sc_dying is set.
 	 */
 	while (__predict_false(sc->sc_exlock != 0)) {
 		error = cv_timedwait_sig(&sc->sc_exlockcv, sc->sc_lock,
@@ -2416,8 +2436,9 @@ audio_unlink(struct audio_softc *sc, aud
 		/* XXX what should I do on error? */
 		if (error == EWOULDBLOCK) {
 			mutex_exit(sc->sc_lock);
-			device_printf(sc->sc_dev,
-			    "%s: cv_timedwait_sig failed %d", __func__, error);
+			audio_printf(sc,
+			    "%s: cv_timedwait_sig failed: errno=%d\n",
+			    __func__, error);
 			return error;
 		}
 	}
@@ -2440,8 +2461,8 @@ audio_unlink(struct audio_softc *sc, aud
 		if (sc->sc_popens == 0 && sc->sc_pbusy) {
 			error = audio_pmixer_halt(sc);
 			if (error) {
-				device_printf(sc->sc_dev,
-				    "halt_output failed with %d (ignored)\n",
+				audio_printf(sc,
+				    "halt_output failed: errno=%d (ignored)\n",
 				    error);
 			}
 		}
@@ -2466,8 +2487,8 @@ audio_unlink(struct audio_softc *sc, aud
 		if (sc->sc_ropens == 0 && sc->sc_rbusy) {
 			error = audio_rmixer_halt(sc);
 			if (error) {
-				device_printf(sc->sc_dev,
-				    "halt_input failed with %d (ignored)\n",
+				audio_printf(sc,
+				    "halt_input failed: errno=%d (ignored)\n",
 				    error);
 			}
 		}
@@ -2585,8 +2606,8 @@ audio_read(struct audio_softc *sc, struc
 			if (error) {
 				audio_track_lock_exit(track);
 				device_printf(sc->sc_dev,
-				    "uiomove(len=%d) failed with %d\n",
-				    len, error);
+				    "%s: uiomove(%d) failed: errno=%d\n",
+				    __func__, len, error);
 				goto abort;
 			}
 			auring_take(usrbuf, len);
@@ -2714,8 +2735,8 @@ audio_write(struct audio_softc *sc, stru
 			if (error) {
 				audio_track_lock_exit(track);
 				device_printf(sc->sc_dev,
-				    "uiomove(len=%d) failed with %d\n",
-				    len, error);
+				    "%s: uiomove(%d) failed: errno=%d\n",
+				    __func__, len, error);
 				goto abort;
 			}
 			auring_push(usrbuf, len);
@@ -3131,7 +3152,7 @@ filt_audioread_detach(struct knote *kn)
 
 	file = kn->kn_hook;
 	sc = file->sc;
-	TRACEF(3, file, "");
+	TRACEF(3, file, "called");
 
 	mutex_enter(sc->sc_lock);
 	SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
@@ -3178,7 +3199,7 @@ filt_audiowrite_detach(struct knote *kn)
 
 	file = kn->kn_hook;
 	sc = file->sc;
-	TRACEF(3, file, "");
+	TRACEF(3, file, "called");
 
 	mutex_enter(sc->sc_lock);
 	SLIST_REMOVE(&sc->sc_wsel.sel_klist, kn, knote, kn_selnext);
@@ -3336,7 +3357,7 @@ audioctl_open(dev_t dev, struct audio_so
 
 	KASSERT(sc->sc_exlock);
 
-	TRACE(1, "");
+	TRACE(1, "called");
 
 	error = fd_allocfile(&fp, &fd);
 	if (error)
@@ -3425,7 +3446,7 @@ audio_realloc_usrbuf(audio_track_t *trac
 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_NONE,
 	    UVM_ADV_RANDOM, 0));
 	if (error) {
-		device_printf(sc->sc_dev, "uvm_map failed with %d\n", error);
+		device_printf(sc->sc_dev, "uvm_map failed: errno=%d\n", error);
 		uao_detach(track->uobj);	/* release reference */
 		goto abort;
 	}
@@ -3433,7 +3454,7 @@ audio_realloc_usrbuf(audio_track_t *trac
 	error = uvm_map_pageable(kernel_map, vstart, vstart + newvsize,
 	    false, 0);
 	if (error) {
-		device_printf(sc->sc_dev, "uvm_map_pageable failed with %d\n",
+		device_printf(sc->sc_dev, "uvm_map_pageable failed: errno=%d\n",
 		    error);
 		uvm_unmap(kernel_map, vstart, vstart + newvsize);
 		/* uvm_unmap also detach uobj */
@@ -4886,9 +4907,9 @@ audio_mixer_init(struct audio_softc *sc,
 		if (rounded != blksize) {
 			if ((rounded * NBBY) % (mixer->hwbuf.fmt.stride *
 			    mixer->hwbuf.fmt.channels) != 0) {
-				device_printf(sc->sc_dev,
-				    "round_blocksize must return blocksize "
-				    "divisible by framesize: "
+				audio_printf(sc,
+				    "round_blocksize returned blocksize "
+				    "indivisible by framesize: "
 				    "blksize=%d rounded=%d "
 				    "stride=%ubit channels=%u\n",
 				    blksize, rounded,
@@ -4917,16 +4938,17 @@ audio_mixer_init(struct audio_softc *sc,
 		TRACE(1, "round_buffersize %zd -> %zd", bufsize, rounded);
 		if (rounded < bufsize) {
 			/* buffersize needs NBLKHW blocks at least. */
-			device_printf(sc->sc_dev,
-			    "buffersize too small: buffersize=%zd blksize=%d\n",
+			audio_printf(sc,
+			    "round_buffersize returned too small buffersize: "
+			    "buffersize=%zd blksize=%d\n",
 			    rounded, blksize);
 			return EINVAL;
 		}
 		if (rounded % blksize != 0) {
 			/* buffersize/blksize constraint mismatch? */
-			device_printf(sc->sc_dev,
-			    "buffersize must be multiple of blksize: "
-			    "buffersize=%zu blksize=%d\n",
+			audio_printf(sc,
+			    "round_buffersize returned buffersize indivisible "
+			    "by blksize: buffersize=%zu blksize=%d\n",
 			    rounded, blksize);
 			return EINVAL;
 		}
@@ -4946,8 +4968,7 @@ audio_mixer_init(struct audio_softc *sc,
 		/* sc_lock is not necessary for allocm */
 		mixer->hwbuf.mem = sc->hw_if->allocm(sc->hw_hdl, mode, bufsize);
 		if (mixer->hwbuf.mem == NULL) {
-			device_printf(sc->sc_dev, "%s: allocm(%zu) failed\n",
-			    __func__, bufsize);
+			audio_printf(sc, "allocm(%zu) failed\n", bufsize);
 			return ENOMEM;
 		}
 	} else {
@@ -5014,8 +5035,7 @@ audio_mixer_init(struct audio_softc *sc,
 		mixer->codecbuf.mem = audio_realloc(mixer->codecbuf.mem, len);
 		if (mixer->codecbuf.mem == NULL) {
 			device_printf(sc->sc_dev,
-			    "%s: malloc codecbuf(%d) failed\n",
-			    __func__, len);
+			    "malloc codecbuf(%d) failed\n", len);
 			error = ENOMEM;
 			goto abort;
 		}
@@ -5490,8 +5510,9 @@ audio_pmixer_output(struct audio_softc *
 			error = sc->hw_if->trigger_output(sc->hw_hdl,
 			    start, end, blksize, audio_pintr, sc, &params);
 			if (error) {
-				device_printf(sc->sc_dev,
-				    "trigger_output failed with %d\n", error);
+				audio_printf(sc,
+				    "trigger_output failed: errno=%d\n",
+				    error);
 				return;
 			}
 		}
@@ -5502,8 +5523,8 @@ audio_pmixer_output(struct audio_softc *
 		error = sc->hw_if->start_output(sc->hw_hdl,
 		    start, blksize, audio_pintr, sc);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "start_output failed with %d\n", error);
+			audio_printf(sc,
+			    "start_output failed: errno=%d\n", error);
 			return;
 		}
 	}
@@ -5529,8 +5550,7 @@ audio_pintr(void *arg)
 		return;
 	if (sc->sc_pbusy == false) {
 #if defined(DIAGNOSTIC)
-		device_printf(sc->sc_dev,
-		    "DIAGNOSTIC: %s raised stray interrupt\n",
+		audio_printf(sc, "DIAGNOSTIC: %s raised stray interrupt\n",
 		    device_xname(sc->hw_dev));
 #endif
 		return;
@@ -5765,8 +5785,9 @@ audio_rmixer_input(struct audio_softc *s
 			error = sc->hw_if->trigger_input(sc->hw_hdl,
 			    start, end, blksize, audio_rintr, sc, &params);
 			if (error) {
-				device_printf(sc->sc_dev,
-				    "trigger_input failed with %d\n", error);
+				audio_printf(sc,
+				    "trigger_input failed: errno=%d\n",
+				    error);
 				return;
 			}
 		}
@@ -5777,8 +5798,8 @@ audio_rmixer_input(struct audio_softc *s
 		error = sc->hw_if->start_input(sc->hw_hdl,
 		    start, blksize, audio_rintr, sc);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "start_input failed with %d\n", error);
+			audio_printf(sc,
+			    "start_input failed: errno=%d\n", error);
 			return;
 		}
 	}
@@ -5804,8 +5825,7 @@ audio_rintr(void *arg)
 		return;
 	if (sc->sc_rbusy == false) {
 #if defined(DIAGNOSTIC)
-		device_printf(sc->sc_dev,
-		    "DIAGNOSTIC: %s raised stray interrupt\n",
+		audio_printf(sc, "DIAGNOSTIC: %s raised stray interrupt\n",
 		    device_xname(sc->hw_dev));
 #endif
 		return;
@@ -5850,7 +5870,7 @@ audio_pmixer_halt(struct audio_softc *sc
 {
 	int error;
 
-	TRACE(2, "");
+	TRACE(2, "called");
 	KASSERT(mutex_owned(sc->sc_lock));
 	KASSERT(sc->sc_exlock);
 
@@ -5880,7 +5900,7 @@ audio_rmixer_halt(struct audio_softc *sc
 {
 	int error;
 
-	TRACE(2, "");
+	TRACE(2, "called");
 	KASSERT(mutex_owned(sc->sc_lock));
 	KASSERT(sc->sc_exlock);
 
@@ -6147,8 +6167,8 @@ audio_softintr_wr(void *cookie)
 
 /*
  * Check (and convert) the format *p came from userland.
- * If successful, it writes back the converted format to *p if necessary
- * and returns 0.  Otherwise returns errno (*p may change even this case).
+ * If successful, it writes back the converted format to *p if necessary and
+ * returns 0.  Otherwise returns errno (*p may be changed even in this case).
  */
 static int
 audio_check_params(audio_format2_t *p)
@@ -6260,8 +6280,8 @@ audio_mixers_init(struct audio_softc *sc
 		}
 		error = audio_mixer_init(sc, AUMODE_PLAY, phwfmt, pfil);
 		if (error) {
-			aprint_error_dev(sc->sc_dev,
-			    "configuring playback mode failed\n");
+			/* audio_mixer_init already displayed error code */
+			audio_printf(sc, "configuring playback mode failed\n");
 			kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
 			sc->sc_pmixer = NULL;
 			return error;
@@ -6278,8 +6298,8 @@ audio_mixers_init(struct audio_softc *sc
 		}
 		error = audio_mixer_init(sc, AUMODE_RECORD, rhwfmt, rfil);
 		if (error) {
-			aprint_error_dev(sc->sc_dev,
-			    "configuring record mode failed\n");
+			/* audio_mixer_init already displayed error code */
+			audio_printf(sc, "configuring record mode failed\n");
 			kmem_free(sc->sc_rmixer, sizeof(*sc->sc_rmixer));
 			sc->sc_rmixer = NULL;
 			return error;
@@ -7209,8 +7229,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 			oldpi->port = au_get_port(sc, &sc->sc_outports);
 		error = au_set_port(sc, &sc->sc_outports, newpi->port);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting play.port=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting play.port=%d failed: errno=%d\n",
 			    newpi->port, error);
 			goto abort;
 		}
@@ -7220,8 +7240,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 			oldri->port = au_get_port(sc, &sc->sc_inports);
 		error = au_set_port(sc, &sc->sc_inports, newri->port);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting record.port=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting record.port=%d failed: errno=%d\n",
 			    newri->port, error);
 			goto abort;
 		}
@@ -7247,8 +7267,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 		error = au_set_gain(sc, &sc->sc_outports,
 		    newpi->gain, pbalance);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting play.gain=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting play.gain=%d failed: errno=%d\n",
 			    newpi->gain, error);
 			goto abort;
 		}
@@ -7257,8 +7277,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 		error = au_set_gain(sc, &sc->sc_inports,
 		    newri->gain, rbalance);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting record.gain=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting record.gain=%d failed: errno=%d\n",
 			    newri->gain, error);
 			goto abort;
 		}
@@ -7267,8 +7287,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 		error = au_set_gain(sc, &sc->sc_outports,
 		    pgain, newpi->balance);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting play.balance=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting play.balance=%d failed: errno=%d\n",
 			    newpi->balance, error);
 			goto abort;
 		}
@@ -7277,8 +7297,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 		error = au_set_gain(sc, &sc->sc_inports,
 		    rgain, newri->balance);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting record.balance=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting record.balance=%d failed: errno=%d\n",
 			    newri->balance, error);
 			goto abort;
 		}
@@ -7289,8 +7309,8 @@ audio_hw_setinfo(struct audio_softc *sc,
 			oldai->monitor_gain = au_get_monitor_gain(sc);
 		error = au_set_monitor_gain(sc, newai->monitor_gain);
 		if (error) {
-			device_printf(sc->sc_dev,
-			    "setting monitor_gain=%d failed with %d\n",
+			audio_printf(sc,
+			    "setting monitor_gain=%d failed: errno=%d\n",
 			    newai->monitor_gain, error);
 			goto abort;
 		}
@@ -7339,8 +7359,7 @@ audio_hw_set_format(struct audio_softc *
 	    &pp, &rp, pfil, rfil);
 	if (error) {
 		mutex_exit(sc->sc_lock);
-		device_printf(sc->sc_dev,
-		    "set_format failed with %d\n", error);
+		audio_printf(sc, "set_format failed: errno=%d\n", error);
 		return error;
 	}
 
@@ -7348,8 +7367,8 @@ audio_hw_set_format(struct audio_softc *
 		error = sc->hw_if->commit_settings(sc->hw_hdl);
 		if (error) {
 			mutex_exit(sc->sc_lock);
-			device_printf(sc->sc_dev,
-			    "commit_settings failed with %d\n", error);
+			audio_printf(sc,
+			    "commit_settings failed: errno=%d\n", error);
 			return error;
 		}
 	}
@@ -8061,7 +8080,7 @@ mixer_close(struct audio_softc *sc, audi
 	error = audio_exlock_enter(sc);
 	if (error)
 		return error;
-	TRACE(1, "");
+	TRACE(1, "called");
 	mixer_async_remove(sc, curproc->p_pid);
 	audio_exlock_exit(sc);
 

Reply via email to