[ALSA] fix potential NULL pointer deref in snd_sb8dsp_midi_interrupt()

First testing if a pointer is NULL and if it is (or might be), proceeding
with code that dereferences that same pointer is clearly a mistake.
This happens in sound/isa/sb/sb8_midi.c::snd_sb8dsp_midi_interrupt()
The patch below reworks the code so this unfortunate case doesn't happen.
Also remove some blank comments.
Found by the Coverity checker as bug #367
Patch is compile testted only due to lack of hardware.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Jesper Juhl 2006-06-13 11:58:12 +02:00 committed by Jaroslav Kysela
parent 6540dffa6e
commit 63eb1e4bd2
1 changed files with 7 additions and 13 deletions

View File

@ -32,9 +32,6 @@
#include <sound/core.h> #include <sound/core.h>
#include <sound/sb.h> #include <sound/sb.h>
/*
*/
irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip) irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip)
{ {
@ -42,10 +39,15 @@ irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb * chip)
int max = 64; int max = 64;
char byte; char byte;
if (chip == NULL || (rmidi = chip->rmidi) == NULL) { if (!chip)
return IRQ_NONE;
rmidi = chip->rmidi;
if (!rmidi) {
inb(SBP(chip, DATA_AVAIL)); /* ack interrupt */ inb(SBP(chip, DATA_AVAIL)); /* ack interrupt */
return IRQ_NONE; return IRQ_NONE;
} }
spin_lock(&chip->midi_input_lock); spin_lock(&chip->midi_input_lock);
while (max-- > 0) { while (max-- > 0) {
if (inb(SBP(chip, DATA_AVAIL)) & 0x80) { if (inb(SBP(chip, DATA_AVAIL)) & 0x80) {
@ -59,10 +61,6 @@ irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb * chip)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
/*
*/
static int snd_sb8dsp_midi_input_open(struct snd_rawmidi_substream *substream) static int snd_sb8dsp_midi_input_open(struct snd_rawmidi_substream *substream)
{ {
unsigned long flags; unsigned long flags;
@ -252,10 +250,6 @@ static void snd_sb8dsp_midi_output_trigger(struct snd_rawmidi_substream *substre
snd_sb8dsp_midi_output_write(substream); snd_sb8dsp_midi_output_write(substream);
} }
/*
*/
static struct snd_rawmidi_ops snd_sb8dsp_midi_output = static struct snd_rawmidi_ops snd_sb8dsp_midi_output =
{ {
.open = snd_sb8dsp_midi_output_open, .open = snd_sb8dsp_midi_output_open,