From 9e958d667c92e5c8bff9d86cecec2b9ca561975a Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Mon, 28 Oct 2024 16:03:37 +0800 Subject: [PATCH] ASoC: SOF: topology: allocate string for tuples The existing code point tuples[*num_copied_tuples].value.s to elem->string which works fine if there is only one topology is handled and all the tuples are handled before the topology fw is released. However, we will handle multiple topologies and the tuples may be used after the topology fw is release. Ues devm_kasprintf to allocate the string for the tuples to avoid invalid access. Signed-off-by: Bard Liao --- sound/soc/sof/topology.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 688cc7ac17148a..234dcc3402ad5a 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -571,7 +571,11 @@ static int sof_copy_tuples(struct snd_sof_dev *sdev, struct snd_soc_tplg_vendor_ continue; tuples[*num_copied_tuples].token = tokens[j].token; - tuples[*num_copied_tuples].value.s = elem->string; + tuples[*num_copied_tuples].value.s = + devm_kasprintf(sdev->dev, GFP_KERNEL, + "%s", elem->string); + if (!tuples[*num_copied_tuples].value.s) + return -ENOMEM; } else { struct snd_soc_tplg_vendor_value_elem *elem;