code: plan9front

Download patch

ref: 36d797f8b638e97c753c9b32214bfefcdda9bc1b
parent: cc17845f6cf72cc78097e996d296cb57e317eb7e
author: cinap_lenrek <>
date: Sun Apr 7 11:19:43 EDT 2024

nusb/audio: fix division by zero error

I have a edirol usb 1.1 soundcard:

ep4.0: audio csp 0x000101 vid 0x08bb did 0x2902 'Burr-Brown from TI ' 'USB Audio CODEC ' 76dd2 xhci

Recent code changes produce the following errors
and seems to leave some volume controls empty,
causing later a division by zero crash.

getvalue: mute: cur: Stall Error
getvalue: volume: cur: Stall Error
getvalue: volume: cur: Stall Error
audio 269: suicide: sys: trap: divide error pc=0x201b25

The device doesnt appear to have digital
volume controls or anything so i'm not really
interested in getting it to work :)

Just getting rid of the crash. The device works
otherwise fine:

% for(i in /dev/audioctlU* /dev/audiostatU*){echo $i; cat $i;}
out on
in on
bufsize      0 buffered      0
fmtout u8c1r32000 u8c1r44100 u8c1r48000 u8c2r32000 u8c2r44100 u8c2r48000 s8c1r32000 s8c1r44100 s8c1r48000 s8c2r32000 s8c2r44100 s8c2r48000 s16c1r32000 s16c1r44100 s16c1r48000 s16c2r32000 s16c2r44100 s16c2r48000
fmtin s8c1r11025 s8c2r11025 s16c1r11025 s16c2r11025 s8c1r8000 s8c2r8000 s8c1r16000 s8c2r16000 s16c1r16000 s16c2r16000 s16c1r22050 s16c2r22050 s16c1r32000 s16c2r32000 s16c1r44100 s16c2r44100 s16c1r48000 s16c2r48000

--- a/sys/src/cmd/nusb/audio/audio.c
+++ b/sys/src/cmd/nusb/audio/audio.c
@@ -754,7 +754,10 @@
 		else {
 			n = (c->max - c->min);
 			x = (c->cur - c->min) * 100;
-			x /= n;
+			if(n == 0)
+				x = 100;
+			else
+				x /= n;
 		x = !!c->cur;