Subject: kern/35220: sys/dev/pci/eso.c: clock source selection is sometimes incorrect
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <stephenm@employees.org>
List: netbsd-bugs
Date: 12/09/2006 11:30:00
>Number:         35220
>Category:       kern
>Synopsis:       sys/dev/pci/eso.c: clock source selection is sometimes incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 09 11:30:00 +0000 2006
>Originator:     Stephen Ma
>Release:        NetBSD 4.99.3
>Organization:
People's Front for the correct spelling of the word "Organisation"
>Environment:
System: NetBSD whitewater.local 4.99.3 NetBSD 4.99.3 (WHITEWATER) #0: Fri Dec 8 05:20:27 PST 2006 stephenm@whitewater.local:/v1/netbsd/obj/src/sys/arch/i386/compile/WHITEWATER i386
Architecture: i386
Machine: i386

>Description:
The clock source selection code in eso_set_params() in the file
sys/dev/pci/eso.c was broken in 1.43. The new code no longer selects
clock 1 at a 48kHz sample rate (and is wrong for some other rates).

>How-To-Repeat:
$ audioplay -f -c 2 -P 16 -s 48000 -e slinear_le /netbsd

>Fix:
--- /v1/netbsd/src/sys/dev/pci/eso.c	2006-11-15 19:03:30.000000000 -0800
+++ /v1/netbsd/obj/src/sys/dev/pci/eso.c	2006-12-08 04:21:35.000000000 -0800
@@ -752,10 +752,8 @@ eso_set_params(void *hdl, int setmode, i
 		r[1] = ESO_CLK1 /
 		    (128 - (rd[1] = 128 - ESO_CLK1 / p->sample_rate));
 
-		if (r[0] > r[1])
-			clk = p->sample_rate - r[1];
-		else
-			clk = p->sample_rate - r[0];
+		clk = ABS((int)p->sample_rate - r[0])
+		    > ABS((int)p->sample_rate - r[1]);
 		srg = rd[clk] | (clk == 1 ? ESO_CLK1_SELECT : 0x00);
 
 		/* Roll-off frequency of 87%, as in the ES1888 driver. */