hal: miscellaneous fixes

Fixes for the following issues reported by KW

21725, 21726, 21727, 21737, 21738, 21739, 21740, 21750,
21751, 21752, 25317, 30602, 32620, 36778, 41817, 41819,
50942, 54468, 54470, 54479, 55569, 54481, 55570, 55571,
58485, 85112, 85122, 85123

Change-Id: I9abef07db7ccdc19789a201eb268a97e1b360cad
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index aa66360..e7a57c8 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -141,6 +141,9 @@
         ALOGV("%s: format - %d", __func__, format);
         if (format != 0) {
             sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format));
+            if (sf_info == NULL)
+                break; /* return whatever was parsed */
+
             sf_info->format = format;
             list_add_tail(&so_info->format_list, &sf_info->list);
         }
@@ -192,6 +195,12 @@
 
     ALOGV("%s", __func__);
     so_info = (struct streams_output_cfg *)calloc(1, sizeof(struct streams_output_cfg));
+
+    if (!so_info) {
+        ALOGE("failed to allocate mem for so_info list element");
+        return;
+    }
+
     while (node) {
         if (strcmp(node->name, FLAGS_TAG) == 0) {
             so_info->flags = parse_flag_names((char *)node->value);
@@ -298,6 +307,11 @@
     }
 
     root = config_node("", "");
+    if (root == NULL) {
+        ALOGE("cfg_list, NULL config root");
+        return;
+    }
+
     config_load(root, data);
     load_output(root, platform, streams_output_cfg_list);