Skip to contentSkip to conversation

ASoC: sn95031: Fix the logic to find free channel

PATCH Applied Axel Lin 4 participants 4 messages Sep 3, 2011 – Sep 4, 2011

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ASoC: sn95031: Fix the logic to find free channel

In the case of no free channel available,
current implementation returns 0 instead of negative errno.

This patch fixes the logic to return -EINVAL if no free channel available.

---
 sound/soc/codecs/sn95031.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
sound/soc/codecs/sn95031.c +3 -5
index 84ffdeb..b4f1cb4 100644
@@ -79,7 +79,7 @@ static void configure_adc(struct snd_soc_codec *sn95031_codec, int val)
  */
 static int find_free_channel(struct snd_soc_codec *sn95031_codec)
 {
-	int ret = 0, i, value;
+	int i, value;
 
 	/* check whether ADC is enabled */
 	value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
@@ -91,12 +91,10 @@ static int find_free_channel(struct snd_soc_codec *sn95031_codec)
 	for (i = 0; i <	SN95031_ADC_CHANLS_MAX; i++) {
 		value = snd_soc_read(sn95031_codec,
 				SN95031_ADC_CHNL_START_ADDR + i);
-		if (value & SN95031_STOPBIT_MASK) {
-			ret = i;
+		if (value & SN95031_STOPBIT_MASK)
 			break;
-		}
 	}
-	return (ret > SN95031_ADC_LOOP_MAX) ? (-EINVAL) : ret;
+	return (i == SN95031_ADC_CHANLS_MAX) ? (-EINVAL) : i;
 }
 
 /* Initialize the ADC for reading micbias values. Can sleep. */
Signature · 1 line
1.7.4.1
Acked-by on v1 1/1
#1 lore raw
Quoted 39 lines · Axel Lin

In the case of no free channel available,
current implementation returns 0 instead of negative errno.

This patch fixes the logic to return -EINVAL if no free channel available.

---
 sound/soc/codecs/sn95031.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
sound/soc/codecs/sn95031.c +1 -1
index 84ffdeb..b4f1cb4 100644
@@ -79,7 +79,7 @@ static void configure_adc(struct snd_soc_codec
 *sn95031_codec, int val)
 */
 static int find_free_channel(struct snd_soc_codec *sn95031_codec)
 {
-       int ret = 0, i, value;
+       int i, value;
 
       /* check whether ADC is enabled */
       value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
sound/soc/codecs/sn95031.c +2 -4
@@ -91,12 +91,10 @@ static int find_free_channel(struct snd_soc_codec
 *sn95031_codec)
       for (i = 0; i < SN95031_ADC_CHANLS_MAX; i++) {
               value = snd_soc_read(sn95031_codec,
                               SN95031_ADC_CHNL_START_ADDR + i);
-               if (value & SN95031_STOPBIT_MASK) {
-                       ret = i;
+               if (value & SN95031_STOPBIT_MASK)
                       break;
-               }
       }
-       return (ret > SN95031_ADC_LOOP_MAX) ? (-EINVAL) : ret;
+       return (i == SN95031_ADC_CHANLS_MAX) ? (-EINVAL) : i;
 }
 
Quoted 7 lines

/* Initialize the ADC for reading micbias values. Can sleep. */
--
1.7.4.1

Btw, this should be posted to alsa-devel.

Acked-by
#2 lore raw
Quoted 54 lines · Liam

On 3 September 2011 06:41, Axel Lin <[email protected]> wrote:

        In the case of no free channel available,
        current implementation returns 0 instead of negative errno.
        
        This patch fixes the logic to return -EINVAL if no free
        channel available.
        
        Signed-off-by: Axel Lin <[email protected]>
        ---
         sound/soc/codecs/sn95031.c |    8 +++-----
         1 files changed, 3 insertions(+), 5 deletions(-)
        
        diff --git a/sound/soc/codecs/sn95031.c
        b/sound/soc/codecs/sn95031.c
        index 84ffdeb..b4f1cb4 100644
        --- a/sound/soc/codecs/sn95031.c
        +++ b/sound/soc/codecs/sn95031.c
        @@ -79,7 +79,7 @@ static void configure_adc(struct
        snd_soc_codec *sn95031_codec, int val)
         */
         static int find_free_channel(struct snd_soc_codec
        *sn95031_codec)
         {
        -       int ret = 0, i, value;
        +       int i, value;
        
               /* check whether ADC is enabled */
               value = snd_soc_read(sn95031_codec, SN95031_ADC1CNTL1);
        @@ -91,12 +91,10 @@ static int find_free_channel(struct
        snd_soc_codec *sn95031_codec)
               for (i = 0; i < SN95031_ADC_CHANLS_MAX; i++) {
                       value = snd_soc_read(sn95031_codec,
                                       SN95031_ADC_CHNL_START_ADDR +
        i);
        -               if (value & SN95031_STOPBIT_MASK) {
        -                       ret = i;
        +               if (value & SN95031_STOPBIT_MASK)
                               break;
        -               }
               }
        -       return (ret > SN95031_ADC_LOOP_MAX) ? (-EINVAL) : ret;
        +       return (i == SN95031_ADC_CHANLS_MAX) ? (-EINVAL) : i;
         }
        
         /* Initialize the ADC for reading micbias values. Can sleep.
        */
        --
        1.7.4.1
Quoted 3 lines

Btw, this should be posted to alsa-devel.

Signature · 1 line
~Vinod
Applied
#3 lore raw
In reply to Axel Lin
Quoted 4 lines · Axel Lin

In the case of no free channel available,
current implementation returns 0 instead of negative errno.

This patch fixes the logic to return -EINVAL if no free channel available.

Applied, thanks.