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

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

hal: Fix race condition in parsing platform info xml

Section is a global variable in platform info parsing functions and
both platform and acdb_extn will call into platform_info_init(). As
a result, there's a race condition happening.

Adding mutex lock to ensure file parsing in atomic.

CRs-Fixed: 2521912
Change-Id: Ic323618057ca2dc21ff60d280cb7a6de3a3271ed
parent 15bb80d3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ struct platform_info {
};

static struct platform_info my_data;
static pthread_mutex_t parser_lock = PTHREAD_MUTEX_INITIALIZER;


struct audio_string_to_enum {
@@ -1447,6 +1448,7 @@ int platform_info_init(const char *filename, void *platform, caller_t caller_typ
    void            *buf;
    char            platform_info_file_name[MIXER_PATH_MAX_LENGTH]= {0};

    pthread_mutex_lock(&parser_lock);
    if (filename == NULL)
        strlcpy(platform_info_file_name, PLATFORM_INFO_XML_PATH,
                MIXER_PATH_MAX_LENGTH);
@@ -1511,5 +1513,6 @@ err_free_parser:
err_close_file:
    fclose(file);
done:
    pthread_mutex_unlock(&parser_lock);
    return ret;
}