]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: qcom: common: validate cpu dai id during parsing
authorSrinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Thu, 2 Apr 2026 08:11:12 +0000 (08:11 +0000)
committerMark Brown <broonie@kernel.org>
Thu, 2 Apr 2026 15:33:43 +0000 (16:33 +0100)
lpass ports numbers have been added but the afe/apm driver never got
updated with new max port value that it uses to store dai specific data.
There are more than one places these values are cached and always become
out of sync.

This will result in array out of bounds and weird driver behaviour.

To catch such issues, first add a single place where we can define max
port and second add a check in common parsing code which can error
out before corrupting the memory with out of bounds array access.

This should help both avoid and catch these type of mistakes in future.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Link: https://patch.msgid.link/20260402081118.348071-8-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/common.c
sound/soc/qcom/common.h
sound/soc/qcom/lpass.h
sound/soc/qcom/qdsp6/q6afe.h
sound/soc/qcom/qdsp6/q6apm.h

index 7ee60a58a3368c9911989ae4e002a46376a9afe2..cf1f3a767ceefa2eeda1f6d63426a455d23b42d3 100644 (file)
@@ -120,6 +120,12 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 
                link->id = args.args[0];
 
+               if (link->id >= LPASS_MAX_PORT) {
+                       dev_err(dev, "%s: Invalid cpu dai id %d\n", link->name, link->id);
+                       ret = -EINVAL;
+                       goto err;
+               }
+
                if (platform) {
                        link->platforms->of_node = of_parse_phandle(platform,
                                        "sound-dai",
index 1b8d3f90bffaf4c418a4b37522dcd1c81bd2a140..ee6662885593c9f15bfbedfe9b923b34b90eb3d8 100644 (file)
@@ -4,8 +4,11 @@
 #ifndef __QCOM_SND_COMMON_H__
 #define __QCOM_SND_COMMON_H__
 
+#include <dt-bindings/sound/qcom,q6afe.h>
 #include <sound/soc.h>
 
+#define LPASS_MAX_PORT                 (SENARY_MI2S_TX + 1)
+
 int qcom_snd_parse_of(struct snd_soc_card *card);
 int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,
                            struct snd_soc_jack *jack, bool *jack_setup);
index de3ec6f594c11c9ca2f75fe9811f5ebe8640b168..68b71039b9814e524da7b098022e49c9f181c039 100644 (file)
 #include <linux/regmap.h>
 #include <dt-bindings/sound/qcom,lpass.h>
 #include <dt-bindings/sound/qcom,q6afe.h>
+#include "common.h"
 #include "lpass-hdmi.h"
 
 #define LPASS_AHBIX_CLOCK_FREQUENCY            131072000
-#define LPASS_MAX_PORTS                        (DISPLAY_PORT_RX_7 + 1)
+#define LPASS_MAX_PORTS                        (LPASS_MAX_PORT)
 #define LPASS_MAX_MI2S_PORTS                   (8)
 #define LPASS_MAX_DMA_CHANNELS                 (8)
 #define LPASS_MAX_HDMI_DMA_CHANNELS            (4)
index a29abe4ce436804cf79752264219e56503618e31..0b8c3ec1315caf23f31037011cb9bf34e5aadfd9 100644 (file)
@@ -2,8 +2,9 @@
 
 #ifndef __Q6AFE_H__
 #define __Q6AFE_H__
+#include "../common.h"
 
-#define AFE_PORT_MAX           137
+#define AFE_PORT_MAX           (LPASS_MAX_PORT)
 
 #define MSM_AFE_PORT_TYPE_RX 0
 #define MSM_AFE_PORT_TYPE_TX 1
index 7ce08b401e31029655f01149a0867b5bd37a7eb6..5cf538397841a7fdbace6fea6b02c8fd3a5230c4 100644 (file)
 #include <linux/of_platform.h>
 #include <linux/jiffies.h>
 #include <linux/soc/qcom/apr.h>
+#include "../common.h"
 #include "audioreach.h"
 
-#define APM_PORT_MAX           127
+#define APM_PORT_MAX           LPASS_MAX_PORT
 #define APM_PORT_MAX_AUDIO_CHAN_CNT 8
 #define PCM_CHANNEL_NULL 0
 #define PCM_CHANNEL_FL    1    /* Front left channel. */