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
diff --git a/audiod/AudioDaemon.cpp b/audiod/AudioDaemon.cpp
index 2c9b5d0..1a40330 100644
--- a/audiod/AudioDaemon.cpp
+++ b/audiod/AudioDaemon.cpp
@@ -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 @@
{
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 @@
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 @@
sndcardFdPair.push_back(std::make_pair(sndcard, fd));
}
}
- line++;
}
ALOGV("%s: %d sound cards detected", __func__, sndcardFdPair.size());
diff --git a/hal/audio_extn/sndmonitor.c b/hal/audio_extn/sndmonitor.c
index eecc448..309a9a8 100644
--- a/hal/audio_extn/sndmonitor.c
+++ b/hal/audio_extn/sndmonitor.c
@@ -162,11 +162,6 @@
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 @@
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;
}