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

Commit 20d3fa66 authored by Weiyin Jiang's avatar Weiyin Jiang Committed by Gerrit - the friendly Code Review server
Browse files

audio: fix misc static errors

Fix accessing index out of array boundary.
Fix dereference of NULL pointer.
Fix use of uninitialized variable.

Change-Id: I77d7be8709bd1c1276ba1b9bb18321083a22c9c2
CRs-Fixed: 2284371
parent fc182748
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -1255,53 +1255,54 @@ bool configure_aptx_enc_format(audio_aptx_encoder_config *aptx_bt_cfg)
    if(aptx_bt_cfg == NULL)
        return false;

    ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK);
    if (!ctl_enc_data) {
        ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed");
        return false;
    }

#ifndef LINUX_ENABLED
    struct aptx_enc_cfg_t aptx_dsp_cfg;
    struct aptx_ad_enc_cfg_t aptx_ad_dsp_cfg;
    if(a2dp.is_aptx_adaptive)
    if(a2dp.is_aptx_adaptive) {
        mixer_size = sizeof(struct aptx_ad_enc_cfg_t);
    else {
        ret = update_aptx_ad_dsp_config(&aptx_ad_dsp_cfg, aptx_bt_cfg);
        sample_rate_backup = aptx_ad_dsp_cfg.custom_cfg.sample_rate;
    } else {
        mixer_size = sizeof(struct aptx_enc_cfg_t);
        sample_rate_backup = aptx_bt_cfg->default_cfg->sampling_rate;
        ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg);
    }
#else
    struct custom_enc_cfg_t aptx_dsp_cfg;
    mixer_size = sizeof(struct custom_enc_cfg_t);
    sample_rate_backup = aptx_bt_cfg->sampling_rate;
#endif

    ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK);
    if (!ctl_enc_data) {
        ALOGE(" ERROR  a2dp encoder CONFIG data mixer control not identifed");
    if (ret) {
        is_configured = false;
        goto fail;
    }

#ifndef LINUX_ENABLED
    if(a2dp.is_aptx_adaptive) {
        ret = update_aptx_ad_dsp_config(&aptx_ad_dsp_cfg, aptx_bt_cfg);
        sample_rate_backup = aptx_ad_dsp_cfg.custom_cfg.sample_rate;
    } else
        ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg);
        ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_ad_dsp_cfg,
                              mixer_size);
    } else {
        ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg,
                              mixer_size);
    }
#else
    struct custom_enc_cfg_t aptx_dsp_cfg;
    mixer_size = sizeof(struct custom_enc_cfg_t);
    sample_rate_backup = aptx_bt_cfg->sampling_rate;
    ret = update_aptx_dsp_config_v1(&aptx_dsp_cfg, aptx_bt_cfg);
#endif

    if (ret) {
        is_configured = false;
        goto fail;
    }
    if(a2dp.is_aptx_adaptive)
        ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_ad_dsp_cfg,
                             mixer_size);
    else
    ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg,
                          mixer_size);
#endif
    if (ret != 0) {
        ALOGE("%s: Failed to set APTX encoder config", __func__);
        is_configured = false;
        goto fail;
    }

    ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                            MIXER_ENC_BIT_FORMAT);
    if (!ctrl_bit_format) {
+5 −0
Original line number Diff line number Diff line
@@ -897,6 +897,11 @@ static int enable_disable_effect(struct audio_device *adev, int effect_type, boo
    ALOGD("%s: effect_type:%d enable:%d", __func__, effect_type, enable);

    usecase = get_usecase_from_list(adev, in->usecase);
    if (usecase == NULL) {
        ALOGE("%s: Could not find the usecase (%d) in the list",
              __func__, in->usecase);
        return -EINVAL;
    }

    ret = platform_get_effect_config_data(usecase->in_snd_device, &effect_config, effect_type);
    if (ret < 0) {
+7 −7
Original line number Diff line number Diff line
@@ -639,7 +639,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
        goto done;
    }
    microphone.num_frequency_responses = atoi(attr[curIdx++]);
    if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
    if (microphone.num_frequency_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
        ALOGE("%s: num_frequency_responses is too large", __func__);
        goto done;
    }
@@ -653,7 +653,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
        uint32_t num_frequencies = 0;
        while (token) {
            microphone.frequency_responses[0][num_frequencies++] = atof(token);
            if (num_frequencies > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
            if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
                ALOGE("%s: num %u of frequency is too large", __func__, num_frequencies);
                goto done;
            }
@@ -668,7 +668,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
        uint32_t num_responses = 0;
        while (token) {
            microphone.frequency_responses[1][num_responses++] = atof(token);
            if (num_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
            if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
                ALOGE("%s: num %u of response is too large", __func__, num_responses);
                goto done;
            }
@@ -724,13 +724,13 @@ static void process_microphone_characteristic(const XML_Char **attr) {
        uint32_t idx = 0;
        while (token) {
            orientation[idx++] = atof(token);
            if (idx > 3) {
            if (idx >= 3) {
                ALOGE("%s: orientation invalid", __func__);
                goto done;
            }
            token = strtok_r(NULL, " ", &context);
        }
        if (idx != 3) {
        if (idx != 2) {
            ALOGE("%s: orientation invalid", __func__);
            goto done;
        }
@@ -754,13 +754,13 @@ static void process_microphone_characteristic(const XML_Char **attr) {
        uint32_t idx = 0;
        while (token) {
            geometric_location[idx++] = atof(token);
            if (idx > 3) {
            if (idx >= 3) {
                ALOGE("%s: geometric_location invalid", __func__);
                goto done;
            }
            token = strtok_r(NULL, " ", &context);
        }
        if (idx != 3) {
        if (idx != 2) {
            ALOGE("%s: geometric_location invalid", __func__);
            goto done;
        }