Skip to contentSkip to conversation

ALSA: Fireface: Use common error handling code in pcm_open()

PATCH In review SF Markus Elfring 3 participants 5 messages Aug 22, 2017 – Aug 23, 2017

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

PATCH 1/1 ALSA: Fireface: Use common error handling code in pcm_open()

From: Markus Elfring <[email protected]>
Date: Tue, 22 Aug 2017 21:45:42 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
 sound/firewire/fireface/ff-pcm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
sound/firewire/fireface/ff-pcm.c +8 -8
index d12a0e3a4219..40975395a64a 100644
@@ -138,16 +138,12 @@ static int pcm_open(struct snd_pcm_substream *substream)
 		return err;
 
 	err = pcm_init_hw_params(ff, substream);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
 	err = ff->spec->protocol->get_clock(ff, &rate, &src);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
 	if (src != SND_FF_CLOCK_SRC_INTERNAL) {
 		for (i = 0; i < CIP_SFC_COUNT; ++i) {
@@ -177,6 +173,10 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	snd_pcm_set_sync(substream);
 
 	return 0;
+
+release_lock:
+	snd_ff_stream_lock_release(ff);
+	return err;
 }
 
 static int pcm_close(struct snd_pcm_substream *substream)
Signature · 1 line
2.14.0
maintainer
#1 lore raw

Hi,

Quoted 39 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 22 Aug 2017 21:45:42 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---
  sound/firewire/fireface/ff-pcm.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
sound/firewire/fireface/ff-pcm.c +4 -8
index d12a0e3a4219..40975395a64a 100644
@@ -138,16 +138,12 @@ static int pcm_open(struct snd_pcm_substream *substream)
  		return err;
 
  	err = pcm_init_hw_params(ff, substream);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
  	err = ff->spec->protocol->get_clock(ff, &rate, &src);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
  	if (src != SND_FF_CLOCK_SRC_INTERNAL) {
  		for (i = 0; i < CIP_SFC_COUNT; ++i) {

sound/firewire/fireface/ff-pcm.c static int pcm_open(struct snd_pcm_substream *substream) · line 182

Quoted 10 lines
sound/firewire/fireface/ff-pcm.c +4 -0
@@ -177,6 +173,10 @@ static int pcm_open(struct snd_pcm_substream *substream)
  	snd_pcm_set_sync(substream);
 
  	return 0;
+
+release_lock:
+	snd_ff_stream_lock_release(ff);
+	return err;
  }
 
  static int pcm_close(struct snd_pcm_substream *substream)

A line to return for err is still left after applying this patch.

148 if (src != SND_FF_CLOCK_SRC_INTERNAL) {
149 for (i = 0; i < CIP_SFC_COUNT; ++i) {
150 if (amdtp_rate_table[i] == rate)
151 break;
152 }
153 /*

154                  * The unit is configured at sampling frequency which packet
155                  * streaming engine can't support.
156                  */

157 if (i >= CIP_SFC_COUNT) {
158 snd_ff_stream_lock_release(ff);
159 return -EIO;
160 }
161

Regards

Takashi Sakamoto

#2 lore raw

PATCH v2 1/1 ALSA: Fireface: Use common error handling code in pcm_open()

From: Markus Elfring <[email protected]>
Date: Wed, 23 Aug 2017 14:45:20 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

---

v2:
It seems that a source code adjustment was requested by Takashi Sakamoto for another if branch.

 sound/firewire/fireface/ff-pcm.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
sound/firewire/fireface/ff-pcm.c +10 -10
index d12a0e3a4219..e3c16308363d 100644
@@ -138,16 +138,12 @@ static int pcm_open(struct snd_pcm_substream *substream)
 		return err;
 
 	err = pcm_init_hw_params(ff, substream);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
 	err = ff->spec->protocol->get_clock(ff, &rate, &src);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
 	if (src != SND_FF_CLOCK_SRC_INTERNAL) {
 		for (i = 0; i < CIP_SFC_COUNT; ++i) {
@@ -159,8 +155,8 @@ static int pcm_open(struct snd_pcm_substream *substream)
 		 * streaming engine can't support.
 		 */
 		if (i >= CIP_SFC_COUNT) {
-			snd_ff_stream_lock_release(ff);
-			return -EIO;
+			err = -EIO;
+			goto release_lock;
 		}
 
 		substream->runtime->hw.rate_min = rate;
@@ -177,6 +173,10 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	snd_pcm_set_sync(substream);
 
 	return 0;
+
+release_lock:
+	snd_ff_stream_lock_release(ff);
+	return err;
 }
 
 static int pcm_close(struct snd_pcm_substream *substream)
Signature · 1 line
2.14.0
maintainer Reviewed-by on v2 1/1
#3 lore raw
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 23 Aug 2017 14:45:20 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

Quoted 8 lines

---

v2:
It seems that a source code adjustment was requested by Takashi Sakamoto for another if branch.

  sound/firewire/fireface/ff-pcm.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
Quoted 37 lines
sound/firewire/fireface/ff-pcm.c +6 -10
index d12a0e3a4219..e3c16308363d 100644
@@ -138,16 +138,12 @@ static int pcm_open(struct snd_pcm_substream *substream)
  		return err;
 
  	err = pcm_init_hw_params(ff, substream);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
  	err = ff->spec->protocol->get_clock(ff, &rate, &src);
-	if (err < 0) {
-		snd_ff_stream_lock_release(ff);
-		return err;
-	}
+	if (err < 0)
+		goto release_lock;
 
  	if (src != SND_FF_CLOCK_SRC_INTERNAL) {
  		for (i = 0; i < CIP_SFC_COUNT; ++i) {
@@ -159,8 +155,8 @@ static int pcm_open(struct snd_pcm_substream *substream)
  		 * streaming engine can't support.
  		 */
  		if (i >= CIP_SFC_COUNT) {
-			snd_ff_stream_lock_release(ff);
-			return -EIO;
+			err = -EIO;
+			goto release_lock;
  		}
 
  		substream->runtime->hw.rate_min = rate;

sound/firewire/fireface/ff-pcm.c static int pcm_open(struct snd_pcm_substream *substream) · line 182

Quoted 10 lines
sound/firewire/fireface/ff-pcm.c +4 -0
@@ -177,6 +173,10 @@ static int pcm_open(struct snd_pcm_substream *substream)
  	snd_pcm_set_sync(substream);
 
  	return 0;
+
+release_lock:
+	snd_ff_stream_lock_release(ff);
+	return err;
  }
 
  static int pcm_close(struct snd_pcm_substream *substream)

Thanks

Takashi Sakamoto

Applied
#4 lore raw
In reply to SF Markus Elfring
Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 23 Aug 2017 14:45:20 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

Quoted 8 lines

This issue was detected by using the Coccinelle software.

---

v2:
It seems that a source code adjustment was requested by Takashi Sakamoto for another if branch.

Applied, thanks.

Takashi