ALSA: rawmidi - Add open check in rawmidi callbacks

The drivers (e.g. mtpav) may call rawmidi functions in irq handlers
even though the streams are not opened. This results in Oops or panic.

This patch adds the rawmidi state check before actually operating the
rawmidi buffers.

Tested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+8
+8
sound/core/rawmidi.c
··· 148 148 149 149 static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *substream,int up) 150 150 { 151 + if (!substream->opened) 152 + return; 151 153 if (up) { 152 154 tasklet_hi_schedule(&substream->runtime->tasklet); 153 155 } else { ··· 160 158 161 159 static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up) 162 160 { 161 + if (!substream->opened) 162 + return; 163 163 substream->ops->trigger(substream, up); 164 164 if (!up && substream->runtime->event) 165 165 tasklet_kill(&substream->runtime->tasklet); ··· 861 857 int result = 0, count1; 862 858 struct snd_rawmidi_runtime *runtime = substream->runtime; 863 859 860 + if (!substream->opened) 861 + return -EBADFD; 864 862 if (runtime->buffer == NULL) { 865 863 snd_printd("snd_rawmidi_receive: input is not active!!!\n"); 866 864 return -EINVAL; ··· 1132 1126 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream, 1133 1127 unsigned char *buffer, int count) 1134 1128 { 1129 + if (!substream->opened) 1130 + return -EBADFD; 1135 1131 count = snd_rawmidi_transmit_peek(substream, buffer, count); 1136 1132 if (count < 0) 1137 1133 return count;