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