audiod: Skip enumerating non-ADSP sound cards

Target crash is observed when a USB headset
is inserted while the target is rebooting.

The crash occurs as AudioDaemon polls on a list
which is corrupt.

Skip enumerating non-ADSP sound cards in AudioDaemon
and sndmonitor to avoid list corruption that fixes
the issue.

CRs-Fixed: 1090587
Change-Id: I0e527182bf4c40e34dbafe8ef3af5490a2bd5798
This commit is contained in:
Satya Krishna Pindiproli 2016-11-17 14:29:07 +05:30 committed by Gerrit - the friendly Code Review server
parent 3e37a700fe
commit 486ddb1f1c
2 changed files with 17 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/* AudioDaemon.cpp
Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@ -69,7 +69,7 @@ namespace android {
{
FILE *fp;
int fd;
char *ptr, *saveptr;
char *ptr, *saveptr, *card_id = NULL;
char buffer[128];
int line = 0;
String8 path;
@ -84,9 +84,21 @@ namespace android {
sndcardFdPair.clear();
memset(buffer, 0x0, sizeof(buffer));
while ((fgets(buffer, sizeof(buffer), fp) != NULL)) {
if (line % 2)
if (line++ % 2)
continue;
ptr = strtok_r(buffer, " [", &saveptr);
if (!ptr)
continue;
card_id = strtok_r(saveptr+1, "]", &saveptr);
if (!card_id)
continue;
//Only consider sound cards associated with ADSP
if ((strncasecmp(card_id, "msm", 3) != 0) &&
(strncasecmp(card_id, "apq", 3) != 0)) {
ALOGD("Skipping non-ADSP sound card %s", card_id);
continue;
}
if (ptr) {
path = "/proc/asound/card";
path += ptr;
@ -101,7 +113,6 @@ namespace android {
sndcardFdPair.push_back(std::make_pair(sndcard, fd));
}
}
line++;
}
ALOGV("%s: %d sound cards detected", __func__, sndcardFdPair.size());

View File

@ -162,11 +162,6 @@ static int add_new_sndcard(int card, int fd)
return 0;
}
static int validate_snd_card(const char *id)
{
return !strncasecmp(id, "msm", 3) ? 0 : -1;
}
static int enum_sndcards()
{
const char *cards = "/proc/asound/cards";
@ -208,7 +203,8 @@ static int enum_sndcards()
continue;
// Only consider sound cards associated with ADSP
if (validate_snd_card((const char *)card_id) < 0) {
if ((strncasecmp(card_id, "msm", 3) != 0) &&
(strncasecmp(card_id, "apq", 3) != 0)) {
ALOGW("Skip over non-ADSP snd card %s", card_id);
continue;
}