Skip to contentSkip to conversation

ASoC: sta32x: shortcut the for loop to get ir and mcs

PATCH Applied Axel Lin 3 participants 3 messages Aug 14, 2011 – Aug 15, 2011

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ASoC: sta32x: shortcut the for loop to get ir and mcs

There is exactly one match or no match at all during the for loop iteration, thus we can break from the for loop once a match is found.

---
 sound/soc/codecs/sta32x.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
sound/soc/codecs/sta32x.c +6 -2
index fbd7eb9..3d155f5 100644
@@ -524,13 +524,17 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
 	rate = params_rate(params);
 	pr_debug("rate: %u\n", rate);
 	for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++)
-		if (interpolation_ratios[i].fs == rate)
+		if (interpolation_ratios[i].fs == rate) {
 			ir = interpolation_ratios[i].ir;
+			break;
+		}
 	if (ir < 0)
 		return -EINVAL;
 	for (i = 0; mclk_ratios[ir][i].ratio; i++)
-		if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk)
+		if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk) {
 			mcs = mclk_ratios[ir][i].mcs;
+			break;
+		}
 	if (mcs < 0)
 		return -EINVAL;
 
Signature · 1 line
1.7.4.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Axel Lin

There is exactly one match or no match at all during the for loop iteration, thus we can break from the for loop once a match is found.

Looks good.

Thanks,
Johannes

Quoted 34 lines
---
 sound/soc/codecs/sta32x.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
sound/soc/codecs/sta32x.c +6 -2
index fbd7eb9..3d155f5 100644
@@ -524,13 +524,17 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
 	rate = params_rate(params);
 	pr_debug("rate: %u\n", rate);
 	for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++)
-		if (interpolation_ratios[i].fs == rate)
+		if (interpolation_ratios[i].fs == rate) {
 			ir = interpolation_ratios[i].ir;
+			break;
+		}
 	if (ir < 0)
 		return -EINVAL;
 	for (i = 0; mclk_ratios[ir][i].ratio; i++)
-		if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk)
+		if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk) {
 			mcs = mclk_ratios[ir][i].mcs;
+			break;
+		}
 	if (mcs < 0)
 		return -EINVAL;
 
Signature · 1 line
1.7.4.1