Skip to contentSkip to conversation

ASoC: cs42l52: Fix off-by-one boundary checking for cs42l52_get_clk()

PATCH In review Axel Lin 1 participant 2 messages Dec 16, 2012

Subsystems (3)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ASoC: cs42l52: Fix off-by-one boundary checking for cs42l52_get_clk()

The caller uses the return value of cs42l52_get_clk as array index, the valid array index is 0 .. ARRAY_SIZE(clk_map_table) - 1. Thus we need to ensure ret is less than ARRAY_SIZE(clk_map_table).

---
 sound/soc/codecs/cs42l52.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/cs42l52.c +1 -1
index 99bb1c6..66817f6 100644
@@ -749,7 +749,7 @@ static int cs42l52_get_clk(int mclk, int rate)
 			}
 		}
 	}
-	if (ret > ARRAY_SIZE(clk_map_table))
+	if (ret >= ARRAY_SIZE(clk_map_table))
 		return -EINVAL;
 	return ret;
 }
Signature · 1 line
1.7.9.5
author
#1 lore raw

2012/12/16 Axel Lin <[email protected]>

Quoted 4 lines

The caller uses the return value of cs42l52_get_clk as array index, the valid array index is 0 .. ARRAY_SIZE(clk_map_table) - 1. Thus we need to ensure ret is less than ARRAY_SIZE(clk_map_table).

Just check the code again, ret is always less than ARRAY_SIZE -1. I think what we missed here is the case no rate is matched.

Axel