From 7b880468804e4f5c974c140d0ddf35b148dfbbb6 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Tue, 1 Jul 2025 16:25:06 -0700 Subject: [PATCH 1/2] [NOT FOR UPSTREAM] ASoC: SOF: ipc4-mtrace: Free trace data in ipc4_mtrace_free() This is required to properly reinitialize trace after freeing without removing the SOF device. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/ipc4-mtrace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/sof/ipc4-mtrace.c b/sound/soc/sof/ipc4-mtrace.c index 8268e4ad793585..df437253c9eaf1 100644 --- a/sound/soc/sof/ipc4-mtrace.c +++ b/sound/soc/sof/ipc4-mtrace.c @@ -574,6 +574,8 @@ static int ipc4_mtrace_init(struct snd_sof_dev *sdev) static void ipc4_mtrace_free(struct snd_sof_dev *sdev) { ipc4_mtrace_disable(sdev); + devm_kfree(sdev->dev, sdev->fw_trace_data); + sdev->fw_trace_data = NULL; } static int sof_ipc4_mtrace_update_pos_all_cores(struct snd_sof_dev *sdev) From 657b7cfe0aed86809fccea73dc08d065bacd8aae Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Tue, 1 Jul 2025 16:27:05 -0700 Subject: [PATCH 2/2] fixup! ASoC: SOF: debug-dsp-ops: Add ops for trace init/free Fix the trace init/free functionality test in the debug ops tester. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/debug-dsp-ops.c | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/sound/soc/sof/debug-dsp-ops.c b/sound/soc/sof/debug-dsp-ops.c index 3a78b123ca8505..442e977e61dc0c 100644 --- a/sound/soc/sof/debug-dsp-ops.c +++ b/sound/soc/sof/debug-dsp-ops.c @@ -65,10 +65,13 @@ static int sof_dsp_ops_set_power_state(struct snd_sof_dev *sdev, char *state) static int sof_dsp_ops_trace_init(struct snd_sof_dev *sdev, bool init) { - if (init) + if (init) { + sdev->fw_trace_is_supported = true; return sof_fw_trace_init(sdev); + } sof_fw_trace_free(sdev); + sdev->fw_trace_is_supported = false; return 0; } @@ -234,13 +237,37 @@ static ssize_t sof_dsp_ops_tester_dfs_write(struct file *file, const char __user struct snd_sof_dev *sdev = dfse->sdev; size_t size; char *string; + int ret; + if (!strcmp(dentry->d_name.name, "init_trace")) { + string = kzalloc(count + 1, GFP_KERNEL); + if (!string) + return -ENOMEM; - if (!strcmp(dentry->d_name.name, "init_trace")) - return sof_dsp_ops_trace_init(sdev, true); + size = simple_write_to_buffer(string, count, ppos, buffer, count); + kfree(string); + + ret = sof_dsp_ops_trace_init(sdev, true); + if (ret < 0) + return ret; + + return size; + } - if (!strcmp(dentry->d_name.name, "free_trace")) - return sof_dsp_ops_trace_init(sdev, false); + if (!strcmp(dentry->d_name.name, "free_trace")) { + string = kzalloc(count + 1, GFP_KERNEL); + if (!string) + return -ENOMEM; + + size = simple_write_to_buffer(string, count, ppos, buffer, count); + kfree(string); + + ret = sof_dsp_ops_trace_init(sdev, false); + if (ret < 0) + return ret; + + return size; + } if (!strcmp(dentry->d_name.name, "unload_fw")) { string = kzalloc(count + 1, GFP_KERNEL);