Skip to contentSkip to conversation

ASoC: ssm2518: Fix off-by-one error by ffs()

PATCH Applied Takashi Iwai 3 participants 3 messages Dec 23, 2013 – Jan 2, 2014

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

PATCH 1/1 ASoC: ssm2518: Fix off-by-one error by ffs()

ffs() returns the bit position from 1, while the ssm2158 driver code assumes it being 0-based. Also, the bit mask computation of the two channel slots are incorrect; it must have worked just casually.

---

I found it casully while checking ab8500 bug.
The patch is untested, so please review/test first, and give Cc to stable if needed.

 sound/soc/codecs/ssm2518.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/ssm2518.c +4 -4
index 95aed552139a..cc8debce752f 100644
@@ -549,13 +549,13 @@ static int ssm2518_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
 		right_slot = 0;
 	} else {
 		/* We assume the left channel < right channel */
-		left_slot = ffs(tx_mask);
-		tx_mask &= ~(1 << tx_mask);
+		left_slot = __ffs(tx_mask);
+		tx_mask &= ~(1 << left_slot);
 		if (tx_mask == 0) {
 			right_slot = left_slot;
 		} else {
-			right_slot = ffs(tx_mask);
-			tx_mask &= ~(1 << tx_mask);
+			right_slot = __ffs(tx_mask);
+			tx_mask &= ~(1 << right_slot);
 		}
 	}
 
Signature · 1 line
1.8.5.2
maintainer Applied
#2 lore raw
In reply to Takashi Iwai
Quoted 3 lines · Takashi Iwai

ffs() returns the bit position from 1, while the ssm2158 driver code assumes it being 0-based. Also, the bit mask computation of the two channel slots are incorrect; it must have worked just casually.

Applied, thanks.