Skip to content

Commit

Permalink
usb: gadget: f_midi: stash substream in gmidi_in_port structure
Browse files Browse the repository at this point in the history
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: Michal Nazarewicz <[email protected]>
Signed-off-by: Felipe Balbi <[email protected]>
  • Loading branch information
mina86 authored and felipebalbi committed Mar 4, 2016
1 parent 413489c commit 4111d49
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/usb/gadget/function/f_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4111d49

Please sign in to comment.