ASoC: qdsp6v2: Add error check for pointer and array index
Add NULL check for the pointer to make sure memory is allocated. Add array boundary check for the index before using the same array. Change-Id: Ifd35ca0c0a1cbeee18d7797ea6b43ea31be0eeba Signed-off-by: Viraja Kommaraju <virajak@codeaurora.org>
This commit is contained in:
parent
85a1cbed68
commit
d355d220ef
3 changed files with 162 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
|
@ -685,6 +685,9 @@ static int msm_audio_smmu_init_legacy(struct device *dev)
|
|||
u32 read_val[2];
|
||||
|
||||
cb = devm_kzalloc(dev, sizeof(struct context_bank_info), GFP_KERNEL);
|
||||
if (!cb)
|
||||
return -ENOMEM;
|
||||
|
||||
ctx_node = of_parse_phandle(dev->of_node, "iommus", 0);
|
||||
if (!ctx_node) {
|
||||
dev_err(dev, "%s Could not find any iommus for audio\n",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
|
@ -175,8 +175,9 @@ int adm_get_topology_for_port_from_copp_id(int port_id, int copp_id)
|
|||
int adm_get_topology_for_port_copp_idx(int port_id, int copp_idx)
|
||||
{
|
||||
int port_idx = adm_validate_and_get_port_index(port_id);
|
||||
if (port_idx < 0) {
|
||||
pr_err("%s: Invalid port id: 0x%x", __func__, port_id);
|
||||
if (port_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
|
||||
pr_err("%s: Invalid port: 0x%x copp id: 0x%x",
|
||||
__func__, port_id, copp_idx);
|
||||
return 0;
|
||||
}
|
||||
return atomic_read(&this_adm.copp.topology[port_idx][copp_idx]);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
|
@ -600,7 +600,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) {
|
||||
pr_debug("%s: AFE port index[%d] invalid!\n",
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
result = -EINVAL;
|
||||
goto done;
|
||||
|
@ -743,6 +743,12 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
ret = -EINVAL;
|
||||
goto fail_cmd;
|
||||
}
|
||||
config.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
|
||||
APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
|
||||
config.hdr.pkt_size = sizeof(config);
|
||||
|
@ -818,6 +824,12 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
ret = -EINVAL;
|
||||
goto fail_cmd;
|
||||
}
|
||||
switch (param_id) {
|
||||
case AFE_PARAM_ID_FBSP_MODE_RX_CFG:
|
||||
config.pdata.module_id = AFE_MODULE_FB_SPKR_PROT_V2_RX;
|
||||
|
@ -990,8 +1002,9 @@ 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) {
|
||||
pr_debug("%s: AFE port index[%d] invalid!\n",
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
ret = -EINVAL;
|
||||
goto fail_cmd;
|
||||
}
|
||||
|
||||
|
@ -1113,7 +1126,7 @@ static int afe_send_port_topology_id(u16 port_id)
|
|||
if (index < 0 || index > AFE_MAX_PORTS) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
goto done;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = afe_get_cal_topology_id(port_id, &topology_id);
|
||||
|
@ -1445,6 +1458,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id = 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -1494,6 +1512,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(tx_port);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, tx_port, ret);
|
||||
|
@ -1574,6 +1597,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(tx_port);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, tx_port, ret);
|
||||
|
@ -1791,6 +1819,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -1872,6 +1905,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -1941,6 +1979,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2007,6 +2050,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2077,6 +2125,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2151,6 +2204,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2226,6 +2284,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2377,6 +2440,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: port id: 0x%x ret %d\n", __func__, port_id, ret);
|
||||
|
@ -2787,6 +2855,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d", __func__, port_id, ret);
|
||||
|
@ -2937,6 +3010,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(rx_port);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d", __func__, rx_port, ret);
|
||||
|
@ -2998,6 +3076,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d",
|
||||
|
@ -3096,6 +3179,11 @@ int afe_start_pseudo_port(u16 port_id)
|
|||
}
|
||||
|
||||
index = q6audio_get_port_index(port_id);
|
||||
if (index < 0 || index > AFE_MAX_PORTS) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d",
|
||||
|
@ -3134,6 +3222,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d",
|
||||
|
@ -3290,6 +3383,11 @@ int afe_stop_pseudo_port(u16 port_id)
|
|||
}
|
||||
|
||||
index = q6audio_get_port_index(port_id);
|
||||
if (index < 0 || index > AFE_MAX_PORTS) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d\n",
|
||||
|
@ -3566,6 +3664,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d",
|
||||
|
@ -3825,6 +3928,11 @@ int afe_unregister_get_events(u16 port_id)
|
|||
}
|
||||
|
||||
index = q6audio_get_port_index(port_id);
|
||||
if (index < 0 || index > AFE_MAX_PORTS) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x ret %d", __func__, port_id, ret);
|
||||
|
@ -4164,6 +4272,12 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
ret = -EINVAL;
|
||||
goto fail_cmd;
|
||||
}
|
||||
ret = wait_event_timeout(this_afe.wait[index],
|
||||
(atomic_read(&this_afe.state) == 0),
|
||||
msecs_to_jiffies(TIMEOUT_MS));
|
||||
|
@ -4196,6 +4310,11 @@ int afe_sidetone(u16 tx_port_id, u16 rx_port_id, u16 enable, uint16_t gain)
|
|||
pr_info("%s: tx_port_id: 0x%x rx_port_id: 0x%x enable:%d gain:%d\n",
|
||||
__func__, tx_port_id, rx_port_id, enable, gain);
|
||||
index = q6audio_get_port_index(rx_port_id);
|
||||
if (index < 0 || index > AFE_MAX_PORTS) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(rx_port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: Invalid port 0x%x %d", __func__, rx_port_id, ret);
|
||||
|
@ -4473,6 +4592,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_validate_port(port_id);
|
||||
if (ret < 0) {
|
||||
pr_warn("%s: Not a valid port id 0x%x ret %d\n",
|
||||
|
@ -4626,6 +4750,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_is_digital_pcm_interface(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: q6audio_is_digital_pcm_interface fail %d\n",
|
||||
|
@ -4787,6 +4916,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_is_digital_pcm_interface(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: q6audio_is_digital_pcm_interface fail %d\n",
|
||||
|
@ -4815,6 +4949,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_is_digital_pcm_interface(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: q6audio_is_digital_pcm_interface fail %d\n",
|
||||
|
@ -4891,6 +5030,11 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = q6audio_is_digital_pcm_interface(port_id);
|
||||
if (ret < 0) {
|
||||
pr_err("%s: q6audio_is_digital_pcm_interface fail %d\n",
|
||||
|
@ -5000,6 +5144,12 @@ 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) {
|
||||
pr_err("%s: AFE port index[%d] invalid!\n",
|
||||
__func__, index);
|
||||
ret = -EINVAL;
|
||||
goto fail_cmd;
|
||||
}
|
||||
calib_resp->hdr.hdr_field =
|
||||
APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
|
||||
APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
|
||||
|
|
Loading…
Add table
Reference in a new issue