Skip to content

Commit

Permalink
ASoC: SOF: topology: add state variable to check topology load state
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
plbossart committed Nov 30, 2018
1 parent 1ba6eed commit 81eb5c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions sound/soc/sof/sof-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ struct snd_sof_dev {
struct list_head dai_list;
struct list_head route_list;
struct snd_soc_component *component;
int tplg_loaded; /* keep track of topology load success */

/* FW configuration */
struct sof_ipc_dma_buffer_data *info_buffer;
Expand Down
13 changes: 13 additions & 0 deletions sound/soc/sof/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,11 @@ int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file)
struct snd_soc_tplg_hdr *hdr;
int ret;

if (sdev->tplg_loaded) {
dev_err(sdev->dev, "topology already loaded ?\n");
return -EINVAL;
}

dev_dbg(sdev->dev, "loading topology:%s\n", file);

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

sdev->tplg_loaded = true;

release_firmware(fw);
return ret;
}
Expand All @@ -2650,6 +2657,10 @@ void snd_sof_free_topology(struct snd_sof_dev *sdev)
int ret;

dev_dbg(sdev->dev, "free topology...\n");
if (!sdev->tplg_loaded) {
dev_dbg(sdev->dev, "No topology loaded, nothing to free ...\n");
return;
}

/* remove routes */
list_for_each_entry_safe(sroute, temp, &sdev->route_list, list) {
Expand All @@ -2665,5 +2676,7 @@ void snd_sof_free_topology(struct snd_sof_dev *sdev)
if (ret < 0)
dev_err(sdev->dev,
"error: tplg component free failed %d\n", ret);

sdev->tplg_loaded = false;
}
EXPORT_SYMBOL(snd_sof_free_topology);

0 comments on commit 81eb5c6

Please sign in to comment.