Browse Source

ASoC: qdsp6: qdafe: fix some off by one bugs

The > should be >= or we could read one element beyond the end of the
port_maps[] array.

Fixes: 7fa2d70f9766 ("ASoC: qdsp6: q6afe: Add q6afe driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Dan Carpenter 7 years ago
parent
commit
c54c1c5ee8
1 changed files with 3 additions and 3 deletions
  1. 3 3
      sound/soc/qcom/qdsp6/q6afe.c

+ 3 - 3
sound/soc/qcom/qdsp6/q6afe.c

@@ -776,7 +776,7 @@ static int q6afe_callback(struct apr_device *adev, struct apr_resp_pkt *data)
  */
  */
 int q6afe_get_port_id(int index)
 int q6afe_get_port_id(int index)
 {
 {
-	if (index < 0 || index > AFE_PORT_MAX)
+	if (index < 0 || index >= AFE_PORT_MAX)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	return port_maps[index].port_id;
 	return port_maps[index].port_id;
@@ -1013,7 +1013,7 @@ int q6afe_port_stop(struct q6afe_port *port)
 
 
 	port_id = port->id;
 	port_id = port->id;
 	index = port->token;
 	index = port->token;
-	if (index < 0 || index > AFE_PORT_MAX) {
+	if (index < 0 || index >= AFE_PORT_MAX) {
 		dev_err(afe->dev, "AFE port index[%d] invalid!\n", index);
 		dev_err(afe->dev, "AFE port index[%d] invalid!\n", index);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
@@ -1354,7 +1354,7 @@ struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id)
 	unsigned long flags;
 	unsigned long flags;
 	int cfg_type;
 	int cfg_type;
 
 
-	if (id < 0 || id > AFE_PORT_MAX) {
+	if (id < 0 || id >= AFE_PORT_MAX) {
 		dev_err(dev, "AFE port token[%d] invalid!\n", id);
 		dev_err(dev, "AFE port token[%d] invalid!\n", id);
 		return ERR_PTR(-EINVAL);
 		return ERR_PTR(-EINVAL);
 	}
 	}