Jelajahi Sumber

ASoC: swr-dmic: fix kw error in dmic_swr_ctrl

Add array bounds check for index before accessing
tx_master_port_map.

Change-Id: I52a8dbdaf40974a45e86b3dca4caa27d88a7b864
Signed-off-by: Vignesh Kulothungan <[email protected]>
Vignesh Kulothungan 4 tahun lalu
induk
melakukan
d6ccb466fb
1 mengubah file dengan 8 tambahan dan 1 penghapusan
  1. 8 1
      asoc/codecs/swr-dmic.c

+ 8 - 1
asoc/codecs/swr-dmic.c

@@ -220,11 +220,18 @@ static int dmic_swr_ctrl(struct snd_soc_dapm_widget *w,
 	u8 port_type = 0;
 	u8 port_id = w->shift;
 
+	if (port_id >= SWR_DMIC_MAX_PORTS)
+	{
+		dev_err(component->dev, "%s: invalid port id: %d\n",
+			__func__, port_id);
+		return -EINVAL;
+	}
+
 	/*
 	 * Port 1 is high quality / 2.4 or 3.072 Mbps
 	 * Port 2 is listen low power / 0.6 or 0.768 Mbps
 	 */
-	if(port_id == SWR_DMIC_HIFI_PORT)
+	if (port_id == SWR_DMIC_HIFI_PORT)
 		ch_rate = SWR_CLK_RATE_2P4MHZ;
 	else
 		ch_rate = SWR_CLK_RATE_0P6MHZ;