[PATCH 2/9] soundwire: amd: allocate pdevinfo and sdw_pdata by ACP revision in probe
From: Vijendar Mukunda
Date: Thu Sep 17 2026 - 05:15:20 EST
Determine the SoundWire manager count from the ACP revision and allocate
the pdevinfo and sdw_pdata arrays dynamically instead of using fixed-size
stack arrays.
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@xxxxxxx>
---
drivers/soundwire/amd_init.c | 37 ++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
index 88004d59322e..15d117172bdb 100644
--- a/drivers/soundwire/amd_init.c
+++ b/drivers/soundwire/amd_init.c
@@ -68,12 +68,12 @@ static int sdw_amd_cleanup(struct sdw_amd_ctx *ctx)
static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
{
+ struct platform_device_info *pdevinfo;
+ struct acp_sdw_pdata *sdw_pdata;
struct sdw_amd_ctx *ctx;
struct acpi_device *adev;
- struct acp_sdw_pdata sdw_pdata[2];
- struct platform_device_info pdevinfo[2];
u32 link_mask;
- int count, index;
+ int count, index, max_manager_count;
int ret;
if (!res)
@@ -88,6 +88,18 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
count = res->count;
dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
+ switch (res->acp_rev) {
+ case ACP63_PCI_REV_ID:
+ case ACP70_PCI_REV_ID:
+ case ACP71_PCI_REV_ID:
+ case ACP72_PCI_REV_ID:
+ max_manager_count = AMD_ACP63_SDW_MAX_MANAGER_COUNT;
+ break;
+ default:
+ dev_err(&adev->dev, "unsupported ACP revision: 0x%x\n", res->acp_rev);
+ return NULL;
+ }
+
ret = amd_enable_sdw_pads(res->mmio_base, res->link_mask, res->parent);
if (ret)
return NULL;
@@ -112,7 +124,20 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
sdw_res->flags = IORESOURCE_MEM;
sdw_res->start = res->addr;
sdw_res->end = res->addr + res->reg_range;
- memset(&pdevinfo, 0, sizeof(pdevinfo));
+
+ sdw_pdata = kcalloc(max_manager_count, sizeof(*sdw_pdata), GFP_KERNEL);
+ if (!sdw_pdata) {
+ kfree(ctx);
+ return NULL;
+ }
+
+ pdevinfo = kcalloc(max_manager_count, sizeof(*pdevinfo), GFP_KERNEL);
+ if (!pdevinfo) {
+ kfree(sdw_pdata);
+ kfree(ctx);
+ return NULL;
+ }
+
link_mask = ctx->link_mask;
for (index = 0; index < count; index++) {
if (!(link_mask & BIT(index)))
@@ -133,6 +158,8 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
if (IS_ERR(ctx->pdev[index]))
goto err;
}
+ kfree(pdevinfo);
+ kfree(sdw_pdata);
return ctx;
err:
while (index--) {
@@ -142,6 +169,8 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
platform_device_unregister(ctx->pdev[index]);
}
+ kfree(pdevinfo);
+ kfree(sdw_pdata);
kfree(ctx);
return NULL;
}
--
2.48.1