Merge "hal: Fixes in audio patch removal and device utilities"
diff --git a/hal/audio_extn/device_utils.c b/hal/audio_extn/device_utils.c
index 8e67273..7bc4150 100644
--- a/hal/audio_extn/device_utils.c
+++ b/hal/audio_extn/device_utils.c
@@ -449,13 +449,14 @@
 bool is_single_device_type_equal(struct listnode *devices,
                                  audio_devices_t type)
 {
-    struct listnode *node = devices;
+    struct listnode *node;
     struct audio_device_info *item = NULL;
 
     if (devices == NULL)
         return false;
 
     if (list_length(devices) == 1) {
+        node = devices->next;
         item = node_to_item(node, struct audio_device_info, list);
         if (item != NULL && (item->type == type))
             return true;
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9b8f29d..ded16ca 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -9881,9 +9881,10 @@
     }
 
     // Remove patch and reset patch handle in stream info
+    patch_type_t patch_type = p_info->patch_type;
     patch_map_remove_l(adev, handle);
-    if (p_info->patch_type == PATCH_PLAYBACK ||
-        p_info->patch_type == PATCH_CAPTURE) {
+    if (patch_type == PATCH_PLAYBACK ||
+        patch_type == PATCH_CAPTURE) {
         struct audio_stream_info *s_info =
             hashmapGet(adev->io_streams_map, (void *) (intptr_t) io_handle);
         if (s_info == NULL) {
@@ -9899,9 +9900,9 @@
     if (stream != NULL) {
         struct listnode devices;
         list_init(&devices);
-        if (p_info->patch_type == PATCH_PLAYBACK)
+        if (patch_type == PATCH_PLAYBACK)
             ret = route_output_stream((struct stream_out *) stream, &devices);
-        else if (p_info->patch_type == PATCH_CAPTURE)
+        else if (patch_type == PATCH_CAPTURE)
             ret = route_input_stream((struct stream_in *) stream, &devices, input_source);
     }