hal: fix crash due to null pointer deference
media server crash observed randomly during bootup due to
speaker protection thread started during bootup uses cached
primary_output stream to configure codec backend, but the
primary_output is not yet opened. Fix it by waiting for
valid primary_output stream before proceeding for speaker
protection calibration processing.
Change-Id: I879b336f8a7fac15cfbbf7d089bb2d19083d8827
CRs-fixed: 1001002
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 1a616df..547266e 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -751,7 +751,8 @@
continue;
} else {
ALOGD("%s: wsa speaker idle %ld,minimum time %ld", __func__, sec, min_idle_time);
- if (!(sec > min_idle_time || handle.trigger_cal)) {
+ if (!adev->primary_output ||
+ ((sec < min_idle_time) && !handle.trigger_cal)) {
pthread_mutex_unlock(&adev->lock);
spkr_calibrate_wait();
continue;