Skip to contentSkip to conversation

ALSA: bebob: Use a signed return type for get_formation_index

PATCH Applied Lucas Tanure 3 participants 3 messages Jan 25, 2016 – Jan 26, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: bebob: Use a signed return type for get_formation_index

The return type "unsigned int" was used by the get_formation_index function
despite of the aspect that it will eventually return a negative error code.
So, change to signed int and get index by reference in the parameters.

Done with the help of Coccinelle.

---
 sound/firewire/bebob/bebob_stream.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
sound/firewire/bebob/bebob_stream.c +7 -4
index 926e5dc..79940e3 100644
@@ -47,14 +47,15 @@ static const unsigned int bridgeco_freq_table[] = {
 	[6] = 0x07,
 };
 
-static unsigned int
-get_formation_index(unsigned int rate)
+static int
+get_formation_index(unsigned int rate, unsigned int *index)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
 		if (snd_bebob_rate_table[i] == rate)
-			return i;
+			*index = i;
+			return 0;
 	}
 	return -EINVAL;
 }
@@ -425,7 +426,9 @@ make_both_connections(struct snd_bebob *bebob, unsigned int rate)
 		goto end;
 
 	/* confirm params for both streams */
-	index = get_formation_index(rate);
+	err = get_formation_index(rate, &index);
+	if (err < 0)
+		goto end;
 	pcm_channels = bebob->tx_stream_formations[index].pcm;
 	midi_channels = bebob->tx_stream_formations[index].midi;
 	err = amdtp_am824_set_parameters(&bebob->tx_stream, rate,
Signature · 1 line
2.7.0
maintainer Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 35 lines · Lucas Tanure

The return type "unsigned int" was used by the get_formation_index function
despite of the aspect that it will eventually return a negative error code.
So, change to signed int and get index by reference in the parameters.

Done with the help of Coccinelle.

---
 sound/firewire/bebob/bebob_stream.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
sound/firewire/bebob/bebob_stream.c +4 -3
index 926e5dc..79940e3 100644
@@ -47,14 +47,15 @@ static const unsigned int bridgeco_freq_table[] = {
 	[6] = 0x07,
 };
 
-static unsigned int
-get_formation_index(unsigned int rate)
+static int
+get_formation_index(unsigned int rate, unsigned int *index)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
 		if (snd_bebob_rate_table[i] == rate)
-			return i;
+			*index = i;
+			return 0;
 	}
 	return -EINVAL;
 }

sound/firewire/bebob/bebob_stream.c make_both_connections(struct snd_bebob *bebob, unsigned int rate) · line 434

Quoted 10 lines
sound/firewire/bebob/bebob_stream.c +3 -1
@@ -425,7 +426,9 @@ make_both_connections(struct snd_bebob *bebob, unsigned int rate)
 		goto end;
 
 	/* confirm params for both streams */
-	index = get_formation_index(rate);
+	err = get_formation_index(rate, &index);
+	if (err < 0)
+		goto end;
 	pcm_channels = bebob->tx_stream_formations[index].pcm;
 	midi_channels = bebob->tx_stream_formations[index].midi;
 	err = amdtp_am824_set_parameters(&bebob->tx_stream, rate,

Indeed, it's my mistake.

This should go for -stable and 4.5-rc2.
CC: [email protected]

Regards

Takashi Sakamoto

Applied
#2 lore raw
In reply to Lucas Tanure
Quoted 8 lines · Lucas Tanure

The return type "unsigned int" was used by the get_formation_index function
despite of the aspect that it will eventually return a negative error code.
So, change to signed int and get index by reference in the parameters.

Done with the help of Coccinelle.

Applied, thanks.

Takashi

Quoted 46 lines
---
 sound/firewire/bebob/bebob_stream.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
sound/firewire/bebob/bebob_stream.c +7 -4
index 926e5dc..79940e3 100644
@@ -47,14 +47,15 @@ static const unsigned int bridgeco_freq_table[] = {
 	[6] = 0x07,
 };
 
-static unsigned int
-get_formation_index(unsigned int rate)
+static int
+get_formation_index(unsigned int rate, unsigned int *index)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
 		if (snd_bebob_rate_table[i] == rate)
-			return i;
+			*index = i;
+			return 0;
 	}
 	return -EINVAL;
 }
@@ -425,7 +426,9 @@ make_both_connections(struct snd_bebob *bebob, unsigned int rate)
 		goto end;
 
 	/* confirm params for both streams */
-	index = get_formation_index(rate);
+	err = get_formation_index(rate, &index);
+	if (err < 0)
+		goto end;
 	pcm_channels = bebob->tx_stream_formations[index].pcm;
 	midi_channels = bebob->tx_stream_formations[index].midi;
 	err = amdtp_am824_set_parameters(&bebob->tx_stream, rate,
Signature · 6 lines
2.7.0

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel