emuxki_set_params(): don't try to set parameters if the appropriate

'voice' is not initialized
This fixes kern/15394 by Onno van der Linden.

Code fragment to trigger the bug:

	AUDIO_INITINFO(&info);
	info.mode = AUMODE_PLAY;
	info.play.channels = 2;
	fd = open("/dev/audioctl0", O_RDWR);
	(void)ioctl(fd, AUDIO_SETINFO, &info);

emuxki_voice_set_audioparms(): g/c check for voice == NULL, this is
never called with null voice
some minor style changes in emuxki_open()/emuxki_close()
This commit is contained in:
jdolecek 2002-01-27 20:38:07 +00:00
parent 872ed866f5
commit 1731882d0a

View File

@ -1,4 +1,4 @@
/* $NetBSD: emuxki.c,v 1.7 2001/12/23 23:14:59 jdolecek Exp $ */
/* $NetBSD: emuxki.c,v 1.8 2002/01/27 20:38:07 jdolecek Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.7 2001/12/23 23:14:59 jdolecek Exp $");
__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.8 2002/01/27 20:38:07 jdolecek Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -1351,19 +1351,6 @@ emuxki_voice_set_audioparms(struct emuxki_voice *voice, u_int8_t stereo,
{
int error;
/*
* Audio driver tried to set recording AND playing params even if
* device opened in play or record only mode ==>
* modified emuxki_set_params.
* Stays here for now just in case ...
*/
if (voice == NULL) {
#ifdef EMUXKI_DEBUG
printf("warning: tried to set unallocated voice params !!\n");
#endif
return (0);
}
if (voice->stereo == stereo && voice->b16 == b16 &&
voice->sample_rate == srate)
return (0);
@ -1595,8 +1582,10 @@ emuxki_open(void *addr, int flags)
if (flags & AUOPEN_WRITE) {
sc->pvoice = emuxki_voice_new(sc, EMU_VOICE_USE_PLAY);
if (sc->pvoice == NULL) {
if (flags & AUOPEN_READ)
if (sc->rvoice) {
emuxki_voice_delete(sc->rvoice);
sc->rvoice = NULL;
}
return (EBUSY);
}
}
@ -1614,12 +1603,14 @@ emuxki_close(void *addr)
#endif
/* No multiple voice support for now */
if (sc->rvoice != NULL)
if (sc->rvoice != NULL) {
emuxki_voice_delete(sc->rvoice);
sc->rvoice = NULL;
if (sc->pvoice != NULL)
sc->rvoice = NULL;
}
if (sc->pvoice != NULL) {
emuxki_voice_delete(sc->pvoice);
sc->pvoice = NULL;
sc->pvoice = NULL;
}
}
static int
@ -1766,17 +1757,27 @@ emuxki_set_params(void *addr, int setmode, int usemode,
struct emuxki_softc *sc = addr;
int mode, error;
struct audio_params *p;
struct emuxki_voice *v;
for (mode = AUMODE_RECORD; mode != -1;
mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
if ((usemode & setmode & mode) == 0)
continue;
p = (mode == AUMODE_PLAY) ? play : rec;
if (mode == AUMODE_PLAY) {
p = play;
v = sc->pvoice;
} else {
p = rec;
v = sc->rvoice;
}
if (v == NULL) {
continue;
}
/* No multiple voice support for now */
if ((error = emuxki_set_vparms((mode == AUMODE_PLAY) ?
sc->pvoice : sc->rvoice, p)))
if ((error = emuxki_set_vparms(v, p)))
return (error);
}