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

Commit 1513f971 authored by Mingshu Pang's avatar Mingshu Pang Committed by Weiyin Jiang
Browse files

hal: Fix misc audio hal issues

- add array index range check when accessing pcm_device_table
- handle calloc failure
- avoid null pointer dereference

CRs-Fixed: 2456514
Change-Id: I2bedf0f1015e646973acba17297267eb317949ce
parent 1aee8389
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4977,6 +4977,10 @@ int split_and_write_audio_haptic_data(struct stream_out *out,

    if (alloc_haptic_buffer) {
        adev->haptic_buffer = (uint8_t *)calloc(1, total_haptic_buffer_size);
        if(adev->haptic_buffer == NULL) {
            ALOGE("%s: failed to allocate mem for dev->haptic_buffer", __func__);
            return -ENOMEM;
        }
        adev->haptic_buffer_size = total_haptic_buffer_size;
    }

+4 −0
Original line number Diff line number Diff line
@@ -3054,6 +3054,10 @@ int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
{
    int device_id = -1;

    if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
        ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
        return device_id;
    }
    if (device_type == PCM_PLAYBACK)
        device_id = pcm_device_table[usecase][0];
    else
+6 −1
Original line number Diff line number Diff line
@@ -423,7 +423,12 @@ void platform_add_backend_name(char *mixer_path, snd_device_t snd_device,

int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
{
    int device_id;
    int device_id = -1;

    if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
        ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
        return device_id;
    }
    if (device_type == PCM_PLAYBACK)
        device_id = pcm_device_table[usecase][0];
    else
+9 −2
Original line number Diff line number Diff line
@@ -3969,7 +3969,12 @@ bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_de

int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
{
    int device_id;
    int device_id = -1;

    if ((usecase >= AUDIO_USECASE_MAX) || (usecase <= USECASE_INVALID)) {
        ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
        return device_id;
    }
    if (device_type == PCM_PLAYBACK)
        device_id = pcm_device_table[usecase][0];
    else
@@ -3998,7 +4003,7 @@ uint64_t getQtime()
int platform_get_delay(void *platform, int pcm_device_id)
{
    int ctl_len = 0;
    struct audio_device *adev = ((struct platform_data *)platform)->adev;
    struct audio_device *adev = NULL;
    struct mixer_ctl *ctl = NULL;
    const char *mixer_ctl_name = "ADSP Path Latency";
    const char *deviceNo = "NN";
@@ -4014,6 +4019,8 @@ int platform_get_delay(void *platform, int pcm_device_id)
        return -EINVAL;
    }

    adev = ((struct platform_data *)platform)->adev;

    // Mixer control format: "ADSP Path Latency NN"
    ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;