Skip to content

Commit 81eb5c6

Browse files
committed
ASoC: SOF: topology: add state variable to check topology load state
With the complicated error flow, we don't have a record of whether the topology was loaded or not. Having a dmesg trace would help indicate an unintended path in error handling. Add a boolean to only load the topology if it's not already loaded, and free the topology if it's loaded, and log errors as needed. Note that the topology_free should itself never result in any crashes. If it does it's a separate issue from identifying bad error handling. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 1ba6eed commit 81eb5c6

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

sound/soc/sof/sof-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ struct snd_sof_dev {
357357
struct list_head dai_list;
358358
struct list_head route_list;
359359
struct snd_soc_component *component;
360+
int tplg_loaded; /* keep track of topology load success */
360361

361362
/* FW configuration */
362363
struct sof_ipc_dma_buffer_data *info_buffer;

sound/soc/sof/topology.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,11 @@ int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file)
26202620
struct snd_soc_tplg_hdr *hdr;
26212621
int ret;
26222622

2623+
if (sdev->tplg_loaded) {
2624+
dev_err(sdev->dev, "topology already loaded ?\n");
2625+
return -EINVAL;
2626+
}
2627+
26232628
dev_dbg(sdev->dev, "loading topology:%s\n", file);
26242629

26252630
ret = request_firmware(&fw, file, sdev->dev);
@@ -2639,6 +2644,8 @@ int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file)
26392644
ret = -EINVAL;
26402645
}
26412646

2647+
sdev->tplg_loaded = true;
2648+
26422649
release_firmware(fw);
26432650
return ret;
26442651
}
@@ -2650,6 +2657,10 @@ void snd_sof_free_topology(struct snd_sof_dev *sdev)
26502657
int ret;
26512658

26522659
dev_dbg(sdev->dev, "free topology...\n");
2660+
if (!sdev->tplg_loaded) {
2661+
dev_dbg(sdev->dev, "No topology loaded, nothing to free ...\n");
2662+
return;
2663+
}
26532664

26542665
/* remove routes */
26552666
list_for_each_entry_safe(sroute, temp, &sdev->route_list, list) {
@@ -2665,5 +2676,7 @@ void snd_sof_free_topology(struct snd_sof_dev *sdev)
26652676
if (ret < 0)
26662677
dev_err(sdev->dev,
26672678
"error: tplg component free failed %d\n", ret);
2679+
2680+
sdev->tplg_loaded = false;
26682681
}
26692682
EXPORT_SYMBOL(snd_sof_free_topology);

0 commit comments

Comments
 (0)