Commit 4111d494 authored by Michal Nazarewicz's avatar Michal Nazarewicz Committed by Felipe Balbi

usb: gadget: f_midi: stash substream in gmidi_in_port structure

For every in_substream, there must be a corresponding gmidi_in_port
structure so it is perfectly viable and some might argue sensible to
stash pointer to the input substream in the gmidi_in_port structure.

This has an added benefit that if in_ports < MAX_PORTS, the whole
f_midi structure takes up less space because only in_ports number of
pointers for in_substream are allocated instead of MAX_PORTS lots of
them.
Signed-off-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
parent 413489c8
......@@ -56,6 +56,7 @@ static const char f_midi_longname[] = "MIDI Gadget";
* USB <- IN endpoint <- rawmidi
*/
struct gmidi_in_port {
struct snd_rawmidi_substream *substream;
int active;
uint8_t cable;
uint8_t state;
......@@ -77,7 +78,6 @@ struct f_midi {
struct snd_rawmidi *rmidi;
u8 ms_id;
struct snd_rawmidi_substream *in_substream[MAX_PORTS];
struct snd_rawmidi_substream *out_substream[MAX_PORTS];
unsigned long out_triggered;
......@@ -520,7 +520,7 @@ static void f_midi_drop_out_substreams(struct f_midi *midi)
for (i = 0; i < midi->in_ports; i++) {
struct gmidi_in_port *port = midi->in_ports_array + i;
struct snd_rawmidi_substream *substream = midi->in_substream[i];
struct snd_rawmidi_substream *substream = port->substream;
if (port->active && substream)
snd_rawmidi_drop_output(substream);
}
......@@ -554,7 +554,7 @@ static int f_midi_do_transmit(struct f_midi *midi, struct usb_ep *ep)
for (i = midi->in_last_port; i < midi->in_ports; ++i) {
struct gmidi_in_port *port = midi->in_ports_array + i;
struct snd_rawmidi_substream *substream = midi->in_substream[i];
struct snd_rawmidi_substream *substream = port->substream;
if (!port->active || !substream)
continue;
......@@ -623,13 +623,15 @@ static void f_midi_in_tasklet(unsigned long data)
static int f_midi_in_open(struct snd_rawmidi_substream *substream)
{
struct f_midi *midi = substream->rmidi->private_data;
struct gmidi_in_port *port;
if (substream->number >= midi->in_ports)
return -EINVAL;
VDBG(midi, "%s()\n", __func__);
midi->in_substream[substream->number] = substream;
midi->in_ports_array[substream->number].state = STATE_UNKNOWN;
port = midi->in_ports_array + substream->number;
port->substream = substream;
port->state = STATE_UNKNOWN;
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment