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

Unverified Commit a4f78a39 authored by Benjamin Legrand's avatar Benjamin Legrand Committed by Michael Bestas
Browse files

Check if hardware_info has been updated or not.

The hardware_info struct is allocated somewhere else and the update_hardware_info_8x16
method will set the structure field. In case of an unknown device,
(e.g. msm8939-florida-snd-card for Motorola lux) the structure is not
initialized. Returning that the structure was not updated allows caller
to release hardware_info struct and set it to NULL.

Current behavior leads to random memory accesses and crashes by hw_info_append_hw_type

Change-Id: I20c067c67de2b1e6a0294fa00d64a64484c7eb54
parent 1002c60c
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ __unused static const snd_device_t helicon_skuab_variant_devices[] = {
    SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
};

static void update_hardware_info_8x16(struct hardware_info *hw_info, const char *snd_card_name)
static int update_hardware_info_8x16(struct hardware_info *hw_info, const char *snd_card_name)
{
    if (!strcmp(snd_card_name, "msm8x16-snd-card")) {
        strlcpy(hw_info->type, "", sizeof(hw_info->type));
@@ -235,7 +235,9 @@ static void update_hardware_info_8x16(struct hardware_info *hw_info, const char
        strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
    } else {
        ALOGW("%s: Not an  8x16/8939/8909 device", __func__);
        return -ENODEV;
    }
    return 0;
}

void *hw_info_init(const char *snd_card_name)
@@ -248,11 +250,7 @@ void *hw_info_init(const char *snd_card_name)
        return NULL;
    }

    if (strstr(snd_card_name, "msm8x16") || strstr(snd_card_name, "msm8939") ||
        strstr(snd_card_name, "msm8909") || strstr(snd_card_name, "msm8x09")) {
        ALOGV("8x16 - variant soundcard");
        update_hardware_info_8x16(hw_info, snd_card_name);
    } else {
    if (update_hardware_info_8x16(hw_info, snd_card_name) < 0) {
        ALOGE("%s: Unsupported target %s:",__func__, snd_card_name);
        free(hw_info);
        hw_info = NULL;