HAL: Fix for crash due to structure mismatch during st deinit

The current implementation of the clear_devices function involves
the audio_device_info structure. However, when a listnode is added
to st_ses_list, the structure sound_trigger_info is used. This leads
to a structural mismatch when clear_devices is called during sound
trigger deinit with st_ses_list. A new function is introduced to
handle the mismatch of structures.

Change-Id: Ida5d5ab2b4a80da5a637a9301465ec3efc16d6ae
diff --git a/hal/audio_extn/soundtrigger.c b/hal/audio_extn/soundtrigger.c
index 41d58f6..b7f27a6 100644
--- a/hal/audio_extn/soundtrigger.c
+++ b/hal/audio_extn/soundtrigger.c
@@ -25,6 +25,10 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
+ * Changes from Qualcomm Innovation Center are provided under the following license:
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
+ *
  */
 #define LOG_TAG "soundtrigger"
 /* #define LOG_NDEBUG 0 */
@@ -872,13 +876,32 @@
 
 }
 
+int clear_device_list(struct listnode *devices)
+{
+     struct listnode *node = NULL, *temp = NULL;
+     struct sound_trigger_info *item = NULL;
+
+     if (devices == NULL)
+         return 0;
+
+     list_for_each_safe (node, temp, devices) {
+         item = node_to_item(node, struct sound_trigger_info, list);
+         if (item != NULL) {
+             list_remove(&item->list);
+             free(item);
+        }
+     }
+
+     return 0;
+}
+
 void audio_extn_sound_trigger_deinit(struct audio_device *adev)
 {
     ALOGI("%s: Enter", __func__);
     if (st_dev && (st_dev->adev == adev) && st_dev->lib_handle) {
         audio_extn_snd_mon_unregister_listener(st_dev);
         dlclose(st_dev->lib_handle);
-        clear_devices(&st_dev->st_ses_list);
+        clear_device_list(&st_dev->st_ses_list);
         free(st_dev);
         st_dev = NULL;
     }