asoc: codecs: Add proper NULL checks and initialize variables

Add null checks and initialize unintialized variables in
wsa macro, wcd937x and wcd937x_slave drivers.

CRs-Fixed: 2328286
Change-Id: I76b8d262e42d2b06ece3a6ecba28ed26b13d4447
Signed-off-by: Tanya Dixit <tdixit@codeaurora.org>
diff --git a/asoc/codecs/bolero/wsa-macro.c b/asoc/codecs/bolero/wsa-macro.c
index 9a6dff3..ec870ad 100644
--- a/asoc/codecs/bolero/wsa-macro.c
+++ b/asoc/codecs/bolero/wsa-macro.c
@@ -756,6 +756,11 @@
 	struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
 	int ret = 0;
 
+	if (regmap == NULL) {
+		dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
+		return -EINVAL;
+	}
+
 	dev_dbg(wsa_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
 		__func__, mclk_enable, dapm, wsa_priv->wsa_mclk_users);
 
@@ -2431,6 +2436,11 @@
 	struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
 	struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
 
+	if (regmap == NULL) {
+		dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
+		return -EINVAL;
+	}
+
 	mutex_lock(&wsa_priv->swr_clk_lock);
 
 	dev_dbg(wsa_priv->dev, "%s: swrm clock %s\n",
diff --git a/asoc/codecs/wcd937x/wcd937x.c b/asoc/codecs/wcd937x/wcd937x.c
index db9f2be..b9ef713 100644
--- a/asoc/codecs/wcd937x/wcd937x.c
+++ b/asoc/codecs/wcd937x/wcd937x.c
@@ -166,7 +166,7 @@
 			char *prop, u8 path)
 {
 	u32 *dt_array, map_size, map_length;
-	u32 port_num, ch_mask, ch_rate, old_port_num = 0;
+	u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
 	u32 slave_port_type, master_port_type;
 	u32 i, ch_iter = 0;
 	int ret = 0;
@@ -188,7 +188,8 @@
 	if (!of_find_property(dev->of_node, prop,
 				&map_size)) {
 		dev_err(dev, "missing port mapping prop %s\n", prop);
-		goto err_pdata_fail;
+		ret = -EINVAL;
+		goto err;
 	}
 
 	map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
@@ -197,13 +198,14 @@
 
 	if (!dt_array) {
 		ret = -ENOMEM;
-		goto err_pdata_fail;
+		goto err;
 	}
 	ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
 				NUM_SWRS_DT_PARAMS * map_length);
 	if (ret) {
 		dev_err(dev, "%s: Failed to read  port mapping from prop %s\n",
 					__func__, prop);
+		ret = -EINVAL;
 		goto err_pdata_fail;
 	}
 
@@ -230,7 +232,8 @@
 
 err_pdata_fail:
 	kfree(dt_array);
-	return -EINVAL;
+err:
+	return ret;
 }
 
 static int wcd937x_tx_connect_port(struct snd_soc_codec *codec,
diff --git a/asoc/codecs/wcd937x/wcd937x_slave.c b/asoc/codecs/wcd937x/wcd937x_slave.c
index 252504f..baab26f 100644
--- a/asoc/codecs/wcd937x/wcd937x_slave.c
+++ b/asoc/codecs/wcd937x/wcd937x_slave.c
@@ -31,6 +31,11 @@
 	uint8_t devnum = 0;
 	struct swr_device *pdev = to_swr_device(dev);
 
+	if (pdev == NULL) {
+		dev_err(dev, "%s: pdev is NULL\n", __func__);
+		return -EINVAL;
+	}
+
 	wcd937x_slave = devm_kzalloc(&pdev->dev,
 				sizeof(struct wcd937x_slave_priv), GFP_KERNEL);
 	if (!wcd937x_slave)
@@ -59,6 +64,11 @@
 	struct wcd937x_slave_priv *wcd937x_slave = NULL;
 	struct swr_device *pdev = to_swr_device(dev);
 
+	if (pdev == NULL) {
+		dev_err(dev, "%s: pdev is NULL\n", __func__);
+		return;
+	}
+
 	wcd937x_slave = swr_get_dev_data(pdev);
 	if (!wcd937x_slave) {
 		dev_err(&pdev->dev, "%s: wcd937x_slave is NULL\n", __func__);