[PATCH 0/3] ASoC: topology: Fixes
Following series performs few cleanups in topology code.
First patch reduces number of prints we get from failure. Second allos TLV controls to be either read or write which should be possible as evidenced by further code in function. Last one cleanups after refactoring of memory handling.
Amadeusz Sławiński (3): ASoC: topology: Remove superfluous error prints ASoC: topology: Allow TLV control to be either read or write ASoC: topology: Optimize soc_tplg_dapm_graph_elems_load behavior
sound/soc/soc-topology.c | 103 ++++++++++----------------------------- 1 file changed, 27 insertions(+), 76 deletions(-)
On 1/11/22 1:05 PM, Amadeusz Sławiński wrote:
Following series performs few cleanups in topology code.
First patch reduces number of prints we get from failure. Second allos TLV controls to be either read or write which should be possible as evidenced by further code in function. Last one cleanups after refactoring of memory handling.
Amadeusz Sławiński (3): ASoC: topology: Remove superfluous error prints ASoC: topology: Allow TLV control to be either read or write ASoC: topology: Optimize soc_tplg_dapm_graph_elems_load behavior
sound/soc/soc-topology.c | 103 ++++++++++----------------------------- 1 file changed, 27 insertions(+), 76 deletions(-)
Thansk for the cleanups.
For the series
Reviewed-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com
soc_tplg_check_elem_count(), already prints an error when applicable, so there is no need to print another one.
Also clean up alignment of arguments in if, so there is no confusion about what is checked and what is executed if condition is true.
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com --- sound/soc/soc-topology.c | 44 ++++++++++------------------------------ 1 file changed, 11 insertions(+), 33 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 078e1dc19ca6..e0f72ddd72c1 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -685,12 +685,9 @@ static int soc_tplg_dbytes_create(struct soc_tplg *tplg, unsigned int count, int err = 0;
if (soc_tplg_check_elem_count(tplg, - sizeof(struct snd_soc_tplg_bytes_control), count, - size, "mixer bytes")) { - dev_err(tplg->dev, "ASoC: Invalid count %d for byte control\n", - count); + sizeof(struct snd_soc_tplg_bytes_control), + count, size, "mixer bytes")) return -EINVAL; - }
for (i = 0; i < count; i++) { be = (struct snd_soc_tplg_bytes_control *)tplg->pos; @@ -763,13 +760,9 @@ static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, int err = 0;
if (soc_tplg_check_elem_count(tplg, - sizeof(struct snd_soc_tplg_mixer_control), - count, size, "mixers")) { - - dev_err(tplg->dev, "ASoC: invalid count %d for controls\n", - count); + sizeof(struct snd_soc_tplg_mixer_control), + count, size, "mixers")) return -EINVAL; - }
for (i = 0; i < count; i++) { mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; @@ -927,13 +920,9 @@ static int soc_tplg_denum_create(struct soc_tplg *tplg, unsigned int count, int err = 0;
if (soc_tplg_check_elem_count(tplg, - sizeof(struct snd_soc_tplg_enum_control), - count, size, "enums")) { - - dev_err(tplg->dev, "ASoC: invalid count %d for enum controls\n", - count); + sizeof(struct snd_soc_tplg_enum_control), + count, size, "enums")) return -EINVAL; - }
for (i = 0; i < count; i++) { ec = (struct snd_soc_tplg_enum_control *)tplg->pos; @@ -1111,13 +1100,9 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, count = le32_to_cpu(hdr->count);
if (soc_tplg_check_elem_count(tplg, - sizeof(struct snd_soc_tplg_dapm_graph_elem), - count, le32_to_cpu(hdr->payload_size), "graph")) { - - dev_err(tplg->dev, "ASoC: invalid count %d for DAPM routes\n", - count); + sizeof(struct snd_soc_tplg_dapm_graph_elem), + count, le32_to_cpu(hdr->payload_size), "graph")) return -EINVAL; - }
dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes for index %d\n", count, hdr->index); @@ -1965,11 +1950,8 @@ static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg, if (soc_tplg_check_elem_count(tplg, size, count, le32_to_cpu(hdr->payload_size), - "PCM DAI")) { - dev_err(tplg->dev, "ASoC: invalid count %d for PCM DAI elems\n", - count); + "PCM DAI")) return -EINVAL; - }
for (i = 0; i < count; i++) { pcm = (struct snd_soc_tplg_pcm *)tplg->pos; @@ -2243,14 +2225,10 @@ static int soc_tplg_link_elems_load(struct soc_tplg *tplg, return -EINVAL; }
- if (soc_tplg_check_elem_count(tplg, - size, count, + if (soc_tplg_check_elem_count(tplg, size, count, le32_to_cpu(hdr->payload_size), - "physical link config")) { - dev_err(tplg->dev, "ASoC: invalid count %d for physical link elems\n", - count); + "physical link config")) return -EINVAL; - }
/* config physical DAI links */ for (i = 0; i < count; i++) {
There is no reason to force readwrite access on TLV controls. It can be either read, write or both. This is further evidenced in code where it performs following checks: if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get) return -EINVAL; if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put) return -EINVAL;
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com --- sound/soc/soc-topology.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index e0f72ddd72c1..9d24184f85f9 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -512,7 +512,8 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
if (le32_to_cpu(hdr->ops.info) == SND_SOC_TPLG_CTL_BYTES && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER - && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE + && (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ + || k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { struct soc_bytes_ext *sbe; struct snd_soc_tplg_bytes_control *be;
On 1/11/22 1:05 PM, Amadeusz Sławiński wrote:
There is no reason to force readwrite access on TLV controls. It can be either read, write or both. This is further evidenced in code where it performs following checks: if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get) return -EINVAL; if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put) return -EINVAL;
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com
Should there be a Fixes tag
Fixes: 1a3232d2f61d ("ASoC: topology: Add support for TLV bytes controls")
?
sound/soc/soc-topology.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index e0f72ddd72c1..9d24184f85f9 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -512,7 +512,8 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
if (le32_to_cpu(hdr->ops.info) == SND_SOC_TPLG_CTL_BYTES && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER
&& k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE
&& (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ
&& k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { struct soc_bytes_ext *sbe; struct snd_soc_tplg_bytes_control *be;|| k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE)
On 1/11/2022 5:48 PM, Pierre-Louis Bossart wrote:
On 1/11/22 1:05 PM, Amadeusz Sławiński wrote:
There is no reason to force readwrite access on TLV controls. It can be either read, write or both. This is further evidenced in code where it performs following checks: if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get) return -EINVAL; if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put) return -EINVAL;
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com
Should there be a Fixes tag
Fixes: 1a3232d2f61d ("ASoC: topology: Add support for TLV bytes controls")
?
I guess it won't hurt, will add and send v2, thanks!
Before commit "ASoC: topology: Change allocations to resource managed" soc_tplg_dapm_graph_elems_load() used to free routes on error. During migration to managed allocations the routes table was left as is, but looking at it again it is unnecessary, so remove routes table and just keep pointer to DAPM route currently being set up. Also remove outdated comments which keep describing old behavior of remove_route() freeing memory. While it still does some cleanup, it leaves freeing memory to framework.
Fixes: ff9226224437 ("ASoC: topology: Change allocations to resource managed") Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com --- sound/soc/soc-topology.c | 56 ++++++++++------------------------------ 1 file changed, 14 insertions(+), 42 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 9d24184f85f9..6c7dc571c006 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1094,7 +1094,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, { struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; struct snd_soc_tplg_dapm_graph_elem *elem; - struct snd_soc_dapm_route **routes; + struct snd_soc_dapm_route *route; int count, i; int ret = 0;
@@ -1108,24 +1108,10 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes for index %d\n", count, hdr->index);
- /* allocate memory for pointer to array of dapm routes */ - routes = kcalloc(count, sizeof(struct snd_soc_dapm_route *), - GFP_KERNEL); - if (!routes) - return -ENOMEM; - - /* - * allocate memory for each dapm route in the array. - * This needs to be done individually so that - * each route can be freed when it is removed in remove_route(). - */ for (i = 0; i < count; i++) { - routes[i] = devm_kzalloc(tplg->dev, sizeof(*routes[i]), GFP_KERNEL); - if (!routes[i]) + route = devm_kzalloc(tplg->dev, sizeof(*route), GFP_KERNEL); + if (!route) return -ENOMEM; - } - - for (i = 0; i < count; i++) { elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos; tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem);
@@ -1146,46 +1132,32 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, break; }
- routes[i]->source = elem->source; - routes[i]->sink = elem->sink; + route->source = elem->source; + route->sink = elem->sink;
/* set to NULL atm for tplg users */ - routes[i]->connected = NULL; + route->connected = NULL; if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) - routes[i]->control = NULL; + route->control = NULL; else - routes[i]->control = elem->control; + route->control = elem->control;
/* add route dobj to dobj_list */ - routes[i]->dobj.type = SND_SOC_DOBJ_GRAPH; - routes[i]->dobj.ops = tplg->ops; - routes[i]->dobj.index = tplg->index; - list_add(&routes[i]->dobj.list, &tplg->comp->dobj_list); + route->dobj.type = SND_SOC_DOBJ_GRAPH; + route->dobj.ops = tplg->ops; + route->dobj.index = tplg->index; + list_add(&route->dobj.list, &tplg->comp->dobj_list);
- ret = soc_tplg_add_route(tplg, routes[i]); + ret = soc_tplg_add_route(tplg, route); if (ret < 0) { dev_err(tplg->dev, "ASoC: topology: add_route failed: %d\n", ret); - /* - * this route was added to the list, it will - * be freed in remove_route() so increment the - * counter to skip it in the error handling - * below. - */ - i++; break; }
/* add route, but keep going if some fail */ - snd_soc_dapm_add_routes(dapm, routes[i], 1); + snd_soc_dapm_add_routes(dapm, route, 1); }
- /* - * free pointer to array of dapm routes as this is no longer needed. - * The memory allocated for each dapm route will be freed - * when it is removed in remove_route(). - */ - kfree(routes); - return ret; }
participants (2)
-
Amadeusz Sławiński
-
Pierre-Louis Bossart