hal: Fix for a native crash in select_devices

In case of speaker protection, stream.in is not filled
and hence when it tries to access stream.in->devices for
spkr-vi-record usecase,crash occurs.In case of HDMI
keep_alive usecase,stream.out is not filled.
Add a null check before accessing stream.in and
stream.out pointers.

Change-Id: I5fafaa71d13ce234908dc2e24979d69a38435f62
CRs-Fixed: 1076923
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 673c17e..d73f92c 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1291,6 +1291,10 @@
     if ((usecase->type == VOICE_CALL) ||
         (usecase->type == VOIP_CALL)  ||
         (usecase->type == PCM_HFP_CALL)) {
+        if(usecase->stream.out == NULL) {
+            ALOGE("%s: stream.out is NULL", __func__);
+            return -EINVAL;
+        }
         out_snd_device = platform_get_output_snd_device(adev->platform,
                                                         usecase->stream.out);
         in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices);
@@ -1334,6 +1338,10 @@
             }
         }
         if (usecase->type == PCM_PLAYBACK) {
+            if (usecase->stream.out == NULL) {
+                ALOGE("%s: stream.out is NULL", __func__);
+                return -EINVAL;
+            }
             usecase->devices = usecase->stream.out->devices;
             in_snd_device = SND_DEVICE_NONE;
             if (out_snd_device == SND_DEVICE_NONE) {
@@ -1346,6 +1354,10 @@
                 }
             }
         } else if (usecase->type == PCM_CAPTURE) {
+            if (usecase->stream.in == NULL) {
+                ALOGE("%s: stream.in is NULL", __func__);
+                return -EINVAL;
+            }
             usecase->devices = usecase->stream.in->device;
             out_snd_device = SND_DEVICE_NONE;
             if (in_snd_device == SND_DEVICE_NONE) {