Subject: kern/7661: successive AUDIO_GETINFO / AUDIO_SETINFO combination fails
To: None <gnats-bugs@gnats.netbsd.org>
From: None <Havard.Eidnes@runit.sintef.no>
List: netbsd-bugs
Date: 05/28/1999 14:22:49
>Number:         7661
>Category:       kern
>Synopsis:       successive AUDIO_GETINFO / AUDIO_SETINFO combination fails
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 28 14:05:01 1999
>Last-Modified:
>Originator:     Havard Eidnes
>Organization:
	RUNIT AS
>Release:        NetBSD 1.4
>Environment:
	
System: NetBSD vader.runit.sintef.no 1.3I NetBSD 1.3I (VADER) #0: Sat Jan 9 18:53:46 MET 1999 he@hugin.runit.sintef.no:/usr/src/sys/arch/i386/compile/VADER i386


>Description:
	Fetching info with AUDIO_GETINFO and just using the returned
	info in an AUDIO_SETINFO ioctl appears to fail (!).

>How-To-Repeat:
	Run this program, and watch it exit in err(1, "AUDIO_SETINFO"):
	
#include <sys/types.h>
#include <sys/audioio.h>
#include <sys/ioctl.h>
#include <fcntl.h>

int
main(argc, argv)
        int argc;
        char **argv;
{
        int fd, sts;
        audio_info_t info;

        fd = open("/dev/audio", O_RDWR);
        if (fd < 0)
                err(1, "open");

        sts = ioctl(fd, AUDIO_GETINFO, &info);
        if (sts != 0)
                err(1, "AUDIO_GETINFO");

        sts = ioctl(fd, AUDIO_SETINFO, &info);
        if (sts != 0)
                err(1, "AUDIO_SETINFO");

        return (0);
}

	A debugger session:

$ gdb a.out
GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386--netbsd"...
(gdb) b main
Breakpoint 1 at 0x180a: file /tmp/t.c, line 14.
(gdb) run
Starting program: /local/store/store/vever/vat-c/src-4.0b2-386netbsd/a.out 

Breakpoint 1, main (argc=1, argv=0xefbfd754) at /tmp/t.c:14
14              fd = open("/dev/audio", O_RDWR);
(gdb) n
15              if (fd < 0)
(gdb) n
18              sts = ioctl(fd, AUDIO_GETINFO, &info);
(gdb) n
19              if (sts != 0)
(gdb) n
22              sts = ioctl(fd, AUDIO_SETINFO, &info);
(gdb) p info
$1 = {play = {sample_rate = 8000, channels = 1, precision = 8, encoding = 1, 
    gain = 0, port = 0, seek = 0, avail_ports = 0, buffer_size = 65536, 
    _ispare = {0}, samples = 0, eof = 0, pause = 0 '\000', error = 0 '\000', 
    waiting = 0 '\000', balance = 32 ' ', cspare = "\000", open = 1 '\001', 
    active = 0 '\000'}, record = {sample_rate = 8000, channels = 1, 
    precision = 8, encoding = 1, gain = 0, port = 1, seek = 0, 
    avail_ports = 5, buffer_size = 65536, _ispare = {0}, samples = 0, eof = 0, 
    pause = 0 '\000', error = 0 '\000', waiting = 0 '\000', balance = 32 ' ', 
    cspare = "\000", open = 1 '\001', active = 0 '\000'}, monitor_gain = 0, 
  blocksize = 400, hiwat = 163, lowat = 122, _ispare1 = 0, mode = 5}
(gdb) n
23              if (sts != 0)
(gdb) n
24                      err(1, "AUDIO_SETINFO");
(gdb) n
a.out: AUDIO_SETINFO: Invalid argument

Program exited with code 01.
(gdb) quit
$

This is with the following audio hardware:

wss0 at isapnp0 port 0x534/4,0x388/4,0x220/16 irq 5 drq 1,0
wss0: CS4236B WSS/SB: CS4236/CS4236B
audio0 at wss0: full duplex


>Fix:
	Sorry, I do not have the foggiest at the moment...
>Audit-Trail:
>Unformatted: