All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: [PATCH 02/15] ALSA: firewire-lib: return error code when amdtp_stream_set_parameters() detects error
Date: Sat, 19 Sep 2015 11:21:49 +0900	[thread overview]
Message-ID: <1442629322-15457-3-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1442629322-15457-1-git-send-email-o-takashi@sakamocchi.jp>

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>
---
 sound/firewire/amdtp.c                      | 22 ++++++++++++----------
 sound/firewire/amdtp.h                      |  8 ++++----
 sound/firewire/bebob/bebob_stream.c         | 13 +++++++++----
 sound/firewire/dice/dice-stream.c           |  5 ++++-
 sound/firewire/fireworks/fireworks_stream.c |  6 ++++--
 sound/firewire/oxfw/oxfw-stream.c           |  5 ++++-
 6 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 2a153d2..2bacb51 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -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);
 
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 4640d2b..3fb8db7 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -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);
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
index 5be5242..c642b79 100644
--- a/sound/firewire/bebob/bebob_stream.c
+++ b/sound/firewire/bebob/bebob_stream.c
@@ -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,
diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
index 07dbd01..c96306a 100644
--- a/sound/firewire/dice/dice-stream.c
+++ b/sound/firewire/dice/dice-stream.c
@@ -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;
 
diff --git a/sound/firewire/fireworks/fireworks_stream.c b/sound/firewire/fireworks/fireworks_stream.c
index 7e353f1..dfefccf 100644
--- a/sound/firewire/fireworks/fireworks_stream.c
+++ b/sound/firewire/fireworks/fireworks_stream.c
@@ -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,
diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 77ad5b9..d119468 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -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));
-- 
2.1.4

  parent reply	other threads:[~2015-09-19  2:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19  2:21 [PATCH 00/15 v3] ALSA: firewire-lib: separate to packet streaming layer and data block processing layer Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 01/15] ALSA: firewire-lib: arrange structure for AMDTP stream Takashi Sakamoto
2015-09-19  2:21 ` Takashi Sakamoto [this message]
2015-09-19  2:21 ` [PATCH 03/15] ALSA: firewire-lib: add an argument for Dice's dual wire mode Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 04/15] ALSA: firewire-lib: add a member of frame_multiplier instead of double_pcm_frames Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 05/15] ALSA: firewire-lib: add helper functions as interfaces between packet streaming layer and data block processing layer Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 06/15] ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 07/15] ALSA: firewire-lib: rename 'amdtp' to 'amdtp-stream' to prepare for functional separation Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 08/15] ALSA: firewire-lib: add data block processing layer for AM824 format Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 09/15] ALSA: firewire-lib: rename parameter setting function for AM824 with FDF field Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 10/15] ALSA: firewire-lib: move PCM substream constraint to AM824 layer Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 11/15] ALSA: firewire-lib: add helper functions to set positions of data channels Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 12/15] ALSA: firewire-lib: move MIDI trigger helper function to AM824 layer Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 13/15] ALSA: firewire-lib: rename PCM format helper function Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 14/15] ALSA: firewire-lib: rename macros with AM824 prefix Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 15/15] ALSA: firewire-lib: complete AM824 data block processing layer Takashi Sakamoto
2015-09-19 16:46 ` [PATCH 00/15 v3] ALSA: firewire-lib: separate to packet streaming layer and " Takashi Iwai
2015-09-29 10:55   ` Takashi Iwai
2015-09-29 12:45     ` Takashi Sakamoto
2015-09-29 12:57       ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442629322-15457-3-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sf.net \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.