[PATCH 2/2] soundwire: qcom: Allocate sruntime array dynamically

From: Srinivas Kandagatla

Date: Wed Jul 01 2026 - 15:32:53 EST


Instead of sizing sruntime[] with a hardcoded SWRM_MAX_DAIS constant,
allocate it at probe time once the actual port count is known from
hardware. This removes the need to keep the constant in sync with
dt-binding limits and naturally supports any future port count increase.

Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
Assisted-by: Claude Sonnet 4.6
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxxxxxxxx>
---
drivers/soundwire/qcom.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index b288218f64b4..603f228f46b5 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -134,7 +134,6 @@
#define TIMEOUT_MS 100
#define QCOM_SWRM_MAX_RD_LEN 0x1
#define DEFAULT_CLK_FREQ 9600000
-#define SWRM_MAX_DAIS 0xF
#define SWR_INVALID_PARAM 0xFF
#define SWR_HSTOP_MAX_VAL 0xF
#define SWR_HSTART_MIN_VAL 0x0
@@ -215,7 +214,7 @@ struct qcom_swrm_ctrl {
u8 wcmd_id;
/* Port numbers are 1 - 14 */
struct qcom_swrm_port_config *pconfig;
- struct sdw_stream_runtime *sruntime[SWRM_MAX_DAIS];
+ struct sdw_stream_runtime **sruntime;
enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
int (*reg_read)(struct qcom_swrm_ctrl *ctrl, int reg, u32 *val);
int (*reg_write)(struct qcom_swrm_ctrl *ctrl, int reg, int val);
@@ -1384,6 +1383,10 @@ static int qcom_swrm_register_dais(struct qcom_swrm_ctrl *ctrl)
struct device *dev = ctrl->dev;
int i;

+ ctrl->sruntime = devm_kcalloc(dev, num_dais, sizeof(*ctrl->sruntime), GFP_KERNEL);
+ if (!ctrl->sruntime)
+ return -ENOMEM;
+
/* PDM dais are only tested for now */
dais = devm_kcalloc(dev, num_dais, sizeof(*dais), GFP_KERNEL);
if (!dais)
--
2.53.0