ALSA: firewire-lib: return error code when amdtp_stream_set_parameters() detects...
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 19 Sep 2015 02:21:49 +0000 (11:21 +0900)
committerTakashi Iwai <tiwai@suse.de>
Tue, 29 Sep 2015 10:35:45 +0000 (12:35 +0200)
Currently, amdtp_stream_set_parameters() returns no error even if wrong
arguments are given. This is not good for streaming layer because drivers
can continue processing ignoring capability of streaming layer.

This commit changes this function to return error code.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/amdtp.c
sound/firewire/amdtp.h
sound/firewire/bebob/bebob_stream.c
sound/firewire/dice/dice-stream.c
sound/firewire/fireworks/fireworks_stream.c
sound/firewire/oxfw/oxfw-stream.c

index 2a153d260836704011b6eadddfbc9b463e1b37b3..2bacb5173ff86f831af404a46923c0f66a2aabcd 100644 (file)
@@ -197,10 +197,10 @@ EXPORT_SYMBOL(amdtp_stream_add_pcm_hw_constraints);
  * The parameters must be set before the stream is started, and must not be
  * changed while the stream is running.
  */
-void amdtp_stream_set_parameters(struct amdtp_stream *s,
-                                unsigned int rate,
-                                unsigned int pcm_channels,
-                                unsigned int midi_ports)
+int amdtp_stream_set_parameters(struct amdtp_stream *s,
+                               unsigned int rate,
+                               unsigned int pcm_channels,
+                               unsigned int midi_ports)
 {
        unsigned int i, sfc, midi_channels;
 
@@ -209,15 +209,15 @@ void amdtp_stream_set_parameters(struct amdtp_stream *s,
        if (WARN_ON(amdtp_stream_running(s)) |
            WARN_ON(pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM) |
            WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))
-               return;
+               return -EINVAL;
 
-       for (sfc = 0; sfc < ARRAY_SIZE(amdtp_rate_table); ++sfc)
+       for (sfc = 0; sfc < ARRAY_SIZE(amdtp_rate_table); ++sfc) {
                if (amdtp_rate_table[sfc] == rate)
-                       goto sfc_found;
-       WARN_ON(1);
-       return;
+                       break;
+       }
+       if (sfc == ARRAY_SIZE(amdtp_rate_table))
+               return -EINVAL;
 
-sfc_found:
        s->pcm_channels = pcm_channels;
        s->sfc = sfc;
        s->data_block_quadlets = s->pcm_channels + midi_channels;
@@ -243,6 +243,8 @@ sfc_found:
         * (The value here is adjusted for midi_ratelimit_per_packet().)
         */
        s->midi_fifo_limit = rate - MIDI_BYTES_PER_SECOND * s->syt_interval + 1;
+
+       return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_set_parameters);
 
index 4640d2b35fb875f9b50e23ebbd84809da7af2afa..3fb8db7ecd68dff9786e735e4c9ea6070b2a2bdc 100644 (file)
@@ -174,10 +174,10 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
                      enum cip_flags flags);
 void amdtp_stream_destroy(struct amdtp_stream *s);
 
-void amdtp_stream_set_parameters(struct amdtp_stream *s,
-                                unsigned int rate,
-                                unsigned int pcm_channels,
-                                unsigned int midi_ports);
+int amdtp_stream_set_parameters(struct amdtp_stream *s,
+                               unsigned int rate,
+                               unsigned int pcm_channels,
+                               unsigned int midi_ports);
 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
 
 int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
index 5be5242e1ed86a535b875346429f5113d37dcad5..c642b79e7ed4a9ce7ad8a7ae6b9f44cede0a8f1c 100644 (file)
@@ -427,12 +427,17 @@ make_both_connections(struct snd_bebob *bebob, unsigned int rate)
        index = get_formation_index(rate);
        pcm_channels = bebob->tx_stream_formations[index].pcm;
        midi_channels = bebob->tx_stream_formations[index].midi;
-       amdtp_stream_set_parameters(&bebob->tx_stream,
-                                   rate, pcm_channels, midi_channels * 8);
+       err = amdtp_stream_set_parameters(&bebob->tx_stream, rate,
+                                         pcm_channels, midi_channels * 8);
+       if (err < 0)
+               goto end;
+
        pcm_channels = bebob->rx_stream_formations[index].pcm;
        midi_channels = bebob->rx_stream_formations[index].midi;
-       amdtp_stream_set_parameters(&bebob->rx_stream,
-                                   rate, pcm_channels, midi_channels * 8);
+       err = amdtp_stream_set_parameters(&bebob->rx_stream, rate,
+                                         pcm_channels, midi_channels * 8);
+       if (err < 0)
+               goto end;
 
        /* establish connections for both streams */
        err = cmp_connection_establish(&bebob->out_conn,
index 07dbd01d7a6bd336d901fa78b83365b44307b1a0..c96306adcae0e49e1764e08a76e407636b26e587 100644 (file)
@@ -133,7 +133,10 @@ static int start_stream(struct snd_dice *dice, struct amdtp_stream *stream,
                stream->double_pcm_frames = false;
        }
 
-       amdtp_stream_set_parameters(stream, rate, pcm_chs, midi_ports);
+       err = amdtp_stream_set_parameters(stream, rate, pcm_chs, midi_ports);
+       if (err < 0)
+               goto end;
+
        if (mode > 1) {
                pcm_chs /= 2;
 
index 7e353f1f7bff359ea8845630aeff2521759e508f..dfefccff3c55b08ca6d0682a8ea989db6115a9f1 100644 (file)
@@ -73,8 +73,10 @@ start_stream(struct snd_efw *efw, struct amdtp_stream *stream,
                midi_ports = efw->midi_in_ports;
        }
 
-       amdtp_stream_set_parameters(stream, sampling_rate,
-                                   pcm_channels, midi_ports);
+       err = amdtp_stream_set_parameters(stream, sampling_rate,
+                                         pcm_channels, midi_ports);
+       if (err < 0)
+               goto end;
 
        /*  establish connection via CMP */
        err = cmp_connection_establish(conn,
index 77ad5b98e806fa694ddd5c0a4c2ae439c78aebf8..d119468fedf45ceb0480fee151106ed5a369c9f1 100644 (file)
@@ -155,7 +155,10 @@ static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream,
                err = -EINVAL;
                goto end;
        }
-       amdtp_stream_set_parameters(stream, rate, pcm_channels, midi_ports);
+       err = amdtp_stream_set_parameters(stream, rate,
+                                         pcm_channels, midi_ports);
+       if (err < 0)
+               goto end;
 
        err = cmp_connection_establish(conn,
                                       amdtp_stream_get_max_payload(stream));