Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38ae225a authored by Xiaoyu Ye's avatar Xiaoyu Ye Committed by Banajit Goswami
Browse files

ASoC: msm: qdsp6v2: Fix range check logic of port index



The case of port index equals AFE_MAX_PORTS is not checked.
Add this corner case to avoid wrong port number.

CRs-Fixed: 1114578
Change-Id: I466cb7d87313e55e9e0bd08a7ab43f3ea36b8b9a
Signed-off-by: default avatarXiaoyu Ye <benyxy@codeaurora.org>
parent 7f504b80
Loading
Loading
Loading
Loading
+35 −35
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ int afe_get_topology(int port_id)
	int topology;
	int port_index = afe_get_port_index(port_id);

	if ((port_index < 0) || (port_index > AFE_MAX_PORTS)) {
	if ((port_index < 0) || (port_index >= AFE_MAX_PORTS)) {
		pr_err("%s: Invalid port index %d\n", __func__, port_index);
		topology = -EINVAL;
		goto done;
@@ -727,7 +727,7 @@ static int afe_send_cal_block(u16 port_id, struct cal_block_data *cal_block)
	}

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		result = -EINVAL;
@@ -871,7 +871,7 @@ static int afe_spk_ramp_dn_cfg(int port)
		goto fail_cmd;
	}
	index = q6audio_get_port_index(port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -952,7 +952,7 @@ static int afe_spk_prot_prepare(int src_port, int dst_port, int param_id,
		goto fail_cmd;
	}
	index = q6audio_get_port_index(src_port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -1198,7 +1198,7 @@ static int afe_send_hw_delay(u16 port_id, u32 rate)
	}

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -1320,7 +1320,7 @@ static int afe_send_port_topology_id(u16 port_id)
	u32 topology_id = 0;

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS - 1) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -1678,7 +1678,7 @@ static int afe_send_slimbus_slave_port_cfg(

	pr_debug("%s: enter, port_id =  0x%x\n", __func__, port_id);
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -1732,7 +1732,7 @@ static int afe_aanc_port_cfg(void *apr, uint16_t tx_port, uint16_t rx_port)
	}

	index = q6audio_get_port_index(tx_port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -1817,7 +1817,7 @@ static int afe_aanc_mod_enable(void *apr, uint16_t tx_port, uint16_t enable)
	}

	index = q6audio_get_port_index(tx_port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2040,7 +2040,7 @@ int afe_send_spdif_clk_cfg(struct afe_param_id_spdif_clk_cfg *cfg,
		return ret;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2126,7 +2126,7 @@ int afe_send_spdif_ch_status_cfg(struct afe_param_id_spdif_ch_status_cfg
		return ret;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2200,7 +2200,7 @@ static int afe_send_cmd_port_start(u16 port_id)

	pr_debug("%s: enter\n", __func__);
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2271,7 +2271,7 @@ int afe_spdif_port_start(u16 port_id, struct afe_spdif_port_config *spdif_port,
	pr_debug("%s: port id: 0x%x\n", __func__, port_id);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2346,7 +2346,7 @@ int afe_send_slot_mapping_cfg(
	pr_debug("%s: port id: 0x%x\n", __func__, port_id);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2425,7 +2425,7 @@ int afe_send_custom_tdm_header_cfg(
	pr_debug("%s: port id: 0x%x\n", __func__, port_id);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2505,7 +2505,7 @@ int afe_tdm_port_start(u16 port_id, struct afe_tdm_port_config *tdm_port,
	pr_debug("%s: port id: 0x%x\n", __func__, port_id);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -2627,7 +2627,7 @@ int afe_port_send_usb_dev_param(u16 port_id, union afe_port_config *afe_config)
		goto exit;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid! for port ID 0x%x\n",
				__func__, index, port_id);
		ret = -EINVAL;
@@ -2821,7 +2821,7 @@ static int __afe_port_start(u16 port_id, union afe_port_config *afe_config,
	pr_debug("%s: port id: 0x%x\n", __func__, port_id);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3378,7 +3378,7 @@ int afe_open(u16 port_id,
	pr_err("%s: port_id 0x%x rate %d\n", __func__, port_id, rate);

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3546,7 +3546,7 @@ int afe_loopback(u16 enable, u16 rx_port, u16 tx_port)
	}

	index = q6audio_get_port_index(rx_port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3612,7 +3612,7 @@ int afe_loopback_gain(u16 port_id, u16 volume)
		goto fail_cmd;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3715,7 +3715,7 @@ int afe_start_pseudo_port(u16 port_id)
	}

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3758,7 +3758,7 @@ int afe_pseudo_port_stop_nowait(u16 port_id)
		return -EINVAL;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -3919,7 +3919,7 @@ int afe_stop_pseudo_port(u16 port_id)
	}

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -4205,7 +4205,7 @@ int afe_cmd_memory_map_nowait(int port_id, phys_addr_t dma_addr_p,
		rtac_set_afe_handle(this_afe.apr);
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -4469,7 +4469,7 @@ int afe_unregister_get_events(u16 port_id)
	}

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -4809,7 +4809,7 @@ int afe_dtmf_generate_rx(int64_t duration_in_ms,
		goto fail_cmd;
	}
	index = q6audio_get_port_index(this_afe.dtmf_gen_rx_portid);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -5047,7 +5047,7 @@ int afe_sidetone_enable(u16 tx_port_id, u16 rx_port_id, bool enable)
	int index;

	index = q6audio_get_port_index(rx_port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -5060,7 +5060,7 @@ int afe_sidetone_enable(u16 tx_port_id, u16 rx_port_id, bool enable)
		goto done;
	}
	index = q6audio_get_port_index(tx_port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;
@@ -5347,7 +5347,7 @@ int afe_close(int port_id)

	port_id = q6audio_convert_virtual_to_portid(port_id);
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -5505,7 +5505,7 @@ int afe_set_lpass_clock(u16 port_id, struct afe_clk_cfg *cfg)
		return ret;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -5671,7 +5671,7 @@ int afe_set_lpass_clock_v2(u16 port_id, struct afe_clk_set *cfg)
	int ret = 0;

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -5704,7 +5704,7 @@ int afe_set_lpass_internal_digital_codec_clock(u16 port_id,
		return ret;
	}
	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -5785,7 +5785,7 @@ int afe_enable_lpass_core_shared_clock(u16 port_id, u32 enable)
	int ret = 0;

	index = q6audio_get_port_index(port_id);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		return -EINVAL;
@@ -6065,7 +6065,7 @@ int afe_spk_prot_get_calib_data(struct afe_spkr_prot_get_vi_calib *calib_resp)
		goto fail_cmd;
	}
	index = q6audio_get_port_index(port);
	if (index < 0 || index > AFE_MAX_PORTS) {
	if (index < 0 || index >= AFE_MAX_PORTS) {
		pr_err("%s: AFE port index[%d] invalid!\n",
				__func__, index);
		ret = -EINVAL;