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

Commit 0a9b63e0 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 9c44776a
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ struct hardware_info {

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

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));
@@ -199,7 +199,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/8952 device", __func__);
        return -ENODEV;
    }
    return 0;
}

void *hw_info_init(const char *snd_card_name)
@@ -212,12 +214,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, "msm8952") ||
        strstr(snd_card_name, "msm8976")) {
        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;