[PATCH 0/6] ASoC: topology: Cleanup patches
Following patches contain minor changes, cleaning up code to be easier to read. Clean up few loops, to be simpler or altogether remove them. Rename some things to make code easier to understand.
Amadeusz Sławiński (6): ASoC: topology: Use for loop instead of while ASoC: topology: Remove unnecessary looping ASoC: topology: Return bool instead of int ASoC: topology: Rename SOC_TPLG_PASS_MIXER to _CONTROL ASoC: topology: Correct error message ASoC: topology: Rename soc_tplg_init_kcontrol() function
sound/soc/soc-topology.c | 455 ++++++++++++++++++--------------------- 1 file changed, 208 insertions(+), 247 deletions(-)
The 'while' loop can be replaced with a 'for' loop, making it more clear about what possible values there are, by having all of it in one place, instead of scattered around.
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 72e50df7052c..bd2155bb6532 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -2550,10 +2550,8 @@ static int soc_tplg_process_headers(struct soc_tplg *tplg) { int ret;
- tplg->pass = SOC_TPLG_PASS_START; - /* process the header types from start to end */ - while (tplg->pass <= SOC_TPLG_PASS_END) { + for (tplg->pass = SOC_TPLG_PASS_START; tplg->pass <= SOC_TPLG_PASS_END; tplg->pass++) { struct snd_soc_tplg_hdr *hdr;
tplg->hdr_pos = tplg->fw->data; @@ -2585,8 +2583,6 @@ static int soc_tplg_process_headers(struct soc_tplg *tplg) hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; }
- /* next data type pass */ - tplg->pass++; }
/* signal DAPM we are complete */ @@ -2653,10 +2649,10 @@ int snd_soc_tplg_component_remove(struct snd_soc_component *comp) { struct snd_card *card = comp->card->snd_card; struct snd_soc_dobj *dobj, *next_dobj; - int pass = SOC_TPLG_PASS_END; + int pass;
/* process the header types from end to start */ - while (pass >= SOC_TPLG_PASS_START) { + for (pass = SOC_TPLG_PASS_END; pass >= SOC_TPLG_PASS_START; pass--) {
/* remove mixer controls */ down_write(&card->controls_rwsem); @@ -2699,7 +2695,6 @@ int snd_soc_tplg_component_remove(struct snd_soc_component *comp) } } up_write(&card->controls_rwsem); - pass--; }
/* let caller know if FW can be freed when no objects are left */
Functions creating kcontrols as written allow for creation of multiple kcontrols at the same time, but in practice they are called for each kcontrol individually. Remove unnecessary loop as code always loops once anyway. This reduces intendation level allowing for some code to be put on one line instead of multiple lines.
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 415 ++++++++++++++++++--------------------- 1 file changed, 192 insertions(+), 223 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index bd2155bb6532..f5446aac8ac6 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -676,175 +676,156 @@ static int soc_tplg_create_tlv(struct soc_tplg *tplg, return 0; }
-static int soc_tplg_dbytes_create(struct soc_tplg *tplg, unsigned int count, - size_t size) +static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size) { struct snd_soc_tplg_bytes_control *be; struct soc_bytes_ext *sbe; struct snd_kcontrol_new kc; - int i; - int err = 0; + int ret = 0;
if (soc_tplg_check_elem_count(tplg, sizeof(struct snd_soc_tplg_bytes_control), - count, size, "mixer bytes")) + 1, size, "mixer bytes")) return -EINVAL;
- for (i = 0; i < count; i++) { - be = (struct snd_soc_tplg_bytes_control *)tplg->pos; + be = (struct snd_soc_tplg_bytes_control *)tplg->pos;
- /* validate kcontrol */ - if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) - return -EINVAL; + /* validate kcontrol */ + if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == + SNDRV_CTL_ELEM_ID_NAME_MAXLEN) + return -EINVAL;
- sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL); - if (sbe == NULL) - return -ENOMEM; + sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL); + if (sbe == NULL) + return -ENOMEM;
- tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + - le32_to_cpu(be->priv.size)); + tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + + le32_to_cpu(be->priv.size));
- dev_dbg(tplg->dev, - "ASoC: adding bytes kcontrol %s with access 0x%x\n", - be->hdr.name, be->hdr.access); - - memset(&kc, 0, sizeof(kc)); - kc.name = be->hdr.name; - kc.private_value = (long)sbe; - kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - kc.access = le32_to_cpu(be->hdr.access); - - sbe->max = le32_to_cpu(be->max); - sbe->dobj.type = SND_SOC_DOBJ_BYTES; - sbe->dobj.ops = tplg->ops; - INIT_LIST_HEAD(&sbe->dobj.list); - - /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, tplg); - if (err) { - soc_control_err(tplg, &be->hdr, be->hdr.name); - break; - } + dev_dbg(tplg->dev, + "ASoC: adding bytes kcontrol %s with access 0x%x\n", + be->hdr.name, be->hdr.access);
- /* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, &kc, - (struct snd_soc_tplg_ctl_hdr *)be); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to init %s\n", - be->hdr.name); - break; - } + memset(&kc, 0, sizeof(kc)); + kc.name = be->hdr.name; + kc.private_value = (long)sbe; + kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kc.access = le32_to_cpu(be->hdr.access);
- /* register control here */ - err = soc_tplg_add_kcontrol(tplg, &kc, - &sbe->dobj.control.kcontrol); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to add %s\n", - be->hdr.name); - break; - } + sbe->max = le32_to_cpu(be->max); + sbe->dobj.type = SND_SOC_DOBJ_BYTES; + sbe->dobj.ops = tplg->ops; + INIT_LIST_HEAD(&sbe->dobj.list);
- list_add(&sbe->dobj.list, &tplg->comp->dobj_list); + /* map io handlers */ + ret = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, tplg); + if (ret) { + soc_control_err(tplg, &be->hdr, be->hdr.name); + goto err; } - return err;
+ /* pass control to driver for optional further init */ + ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)be); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to init %s\n", be->hdr.name); + goto err; + } + + /* register control here */ + ret = soc_tplg_add_kcontrol(tplg, &kc, &sbe->dobj.control.kcontrol); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to add %s\n", be->hdr.name); + goto err; + } + + list_add(&sbe->dobj.list, &tplg->comp->dobj_list); + +err: + return ret; }
-static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, - size_t size) +static int soc_tplg_dmixer_create(struct soc_tplg *tplg, size_t size) { struct snd_soc_tplg_mixer_control *mc; struct soc_mixer_control *sm; struct snd_kcontrol_new kc; - int i; - int err = 0; + int ret = 0;
if (soc_tplg_check_elem_count(tplg, sizeof(struct snd_soc_tplg_mixer_control), - count, size, "mixers")) + 1, size, "mixers")) return -EINVAL;
- for (i = 0; i < count; i++) { - mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; + mc = (struct snd_soc_tplg_mixer_control *)tplg->pos;
- /* validate kcontrol */ - if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) - return -EINVAL; + /* validate kcontrol */ + if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == + SNDRV_CTL_ELEM_ID_NAME_MAXLEN) + return -EINVAL;
- sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL); - if (sm == NULL) - return -ENOMEM; - tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + - le32_to_cpu(mc->priv.size)); + sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL); + if (sm == NULL) + return -ENOMEM; + tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + + le32_to_cpu(mc->priv.size));
- dev_dbg(tplg->dev, - "ASoC: adding mixer kcontrol %s with access 0x%x\n", - mc->hdr.name, mc->hdr.access); - - memset(&kc, 0, sizeof(kc)); - kc.name = mc->hdr.name; - kc.private_value = (long)sm; - kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - kc.access = le32_to_cpu(mc->hdr.access); - - /* we only support FL/FR channel mapping atm */ - sm->reg = tplc_chan_get_reg(tplg, mc->channel, - SNDRV_CHMAP_FL); - sm->rreg = tplc_chan_get_reg(tplg, mc->channel, - SNDRV_CHMAP_FR); - sm->shift = tplc_chan_get_shift(tplg, mc->channel, - SNDRV_CHMAP_FL); - sm->rshift = tplc_chan_get_shift(tplg, mc->channel, - SNDRV_CHMAP_FR); - - sm->max = le32_to_cpu(mc->max); - sm->min = le32_to_cpu(mc->min); - sm->invert = le32_to_cpu(mc->invert); - sm->platform_max = le32_to_cpu(mc->platform_max); - sm->dobj.index = tplg->index; - sm->dobj.ops = tplg->ops; - sm->dobj.type = SND_SOC_DOBJ_MIXER; - INIT_LIST_HEAD(&sm->dobj.list); - - /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, tplg); - if (err) { - soc_control_err(tplg, &mc->hdr, mc->hdr.name); - break; - } + dev_dbg(tplg->dev, + "ASoC: adding mixer kcontrol %s with access 0x%x\n", + mc->hdr.name, mc->hdr.access);
- /* create any TLV data */ - err = soc_tplg_create_tlv(tplg, &kc, &mc->hdr); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to create TLV %s\n", - mc->hdr.name); - break; - } + memset(&kc, 0, sizeof(kc)); + kc.name = mc->hdr.name; + kc.private_value = (long)sm; + kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kc.access = le32_to_cpu(mc->hdr.access);
- /* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, &kc, - (struct snd_soc_tplg_ctl_hdr *) mc); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to init %s\n", - mc->hdr.name); - break; - } + /* we only support FL/FR channel mapping atm */ + sm->reg = tplc_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FL); + sm->rreg = tplc_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FR); + sm->shift = tplc_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FL); + sm->rshift = tplc_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FR);
- /* register control here */ - err = soc_tplg_add_kcontrol(tplg, &kc, - &sm->dobj.control.kcontrol); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to add %s\n", - mc->hdr.name); - break; - } + sm->max = le32_to_cpu(mc->max); + sm->min = le32_to_cpu(mc->min); + sm->invert = le32_to_cpu(mc->invert); + sm->platform_max = le32_to_cpu(mc->platform_max); + sm->dobj.index = tplg->index; + sm->dobj.ops = tplg->ops; + sm->dobj.type = SND_SOC_DOBJ_MIXER; + INIT_LIST_HEAD(&sm->dobj.list); + + /* map io handlers */ + ret = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, tplg); + if (ret) { + soc_control_err(tplg, &mc->hdr, mc->hdr.name); + goto err; + }
- list_add(&sm->dobj.list, &tplg->comp->dobj_list); + /* create any TLV data */ + ret = soc_tplg_create_tlv(tplg, &kc, &mc->hdr); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to create TLV %s\n", mc->hdr.name); + goto err; }
- return err; + /* pass control to driver for optional further init */ + ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)mc); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to init %s\n", mc->hdr.name); + goto err; + } + + /* register control here */ + ret = soc_tplg_add_kcontrol(tplg, &kc, &sm->dobj.control.kcontrol); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to add %s\n", mc->hdr.name); + goto err; + } + + list_add(&sm->dobj.list, &tplg->comp->dobj_list); + +err: + return ret; }
static int soc_tplg_denum_create_texts(struct soc_tplg *tplg, struct soc_enum *se, @@ -911,117 +892,108 @@ static int soc_tplg_denum_create_values(struct soc_tplg *tplg, struct soc_enum * return 0; }
-static int soc_tplg_denum_create(struct soc_tplg *tplg, unsigned int count, - size_t size) +static int soc_tplg_denum_create(struct soc_tplg *tplg, size_t size) { struct snd_soc_tplg_enum_control *ec; struct soc_enum *se; struct snd_kcontrol_new kc; - int i; - int err = 0; + int ret = 0;
if (soc_tplg_check_elem_count(tplg, sizeof(struct snd_soc_tplg_enum_control), - count, size, "enums")) + 1, size, "enums")) return -EINVAL;
- for (i = 0; i < count; i++) { - ec = (struct snd_soc_tplg_enum_control *)tplg->pos; + ec = (struct snd_soc_tplg_enum_control *)tplg->pos;
- /* validate kcontrol */ - if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) - return -EINVAL; + /* validate kcontrol */ + if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == + SNDRV_CTL_ELEM_ID_NAME_MAXLEN) + return -EINVAL;
- se = devm_kzalloc(tplg->dev, (sizeof(*se)), GFP_KERNEL); - if (se == NULL) - return -ENOMEM; + se = devm_kzalloc(tplg->dev, (sizeof(*se)), GFP_KERNEL); + if (se == NULL) + return -ENOMEM;
- tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + - le32_to_cpu(ec->priv.size)); + tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + + le32_to_cpu(ec->priv.size));
- dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", - ec->hdr.name, ec->items); + dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", + ec->hdr.name, ec->items);
- memset(&kc, 0, sizeof(kc)); - kc.name = ec->hdr.name; - kc.private_value = (long)se; - kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - kc.access = le32_to_cpu(ec->hdr.access); + memset(&kc, 0, sizeof(kc)); + kc.name = ec->hdr.name; + kc.private_value = (long)se; + kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + kc.access = le32_to_cpu(ec->hdr.access);
- se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); - se->shift_l = tplc_chan_get_shift(tplg, ec->channel, - SNDRV_CHMAP_FL); - se->shift_r = tplc_chan_get_shift(tplg, ec->channel, - SNDRV_CHMAP_FL); + se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); + se->shift_l = tplc_chan_get_shift(tplg, ec->channel, + SNDRV_CHMAP_FL); + se->shift_r = tplc_chan_get_shift(tplg, ec->channel, + SNDRV_CHMAP_FL);
- se->mask = le32_to_cpu(ec->mask); - se->dobj.index = tplg->index; - se->dobj.type = SND_SOC_DOBJ_ENUM; - se->dobj.ops = tplg->ops; - INIT_LIST_HEAD(&se->dobj.list); + se->mask = le32_to_cpu(ec->mask); + se->dobj.index = tplg->index; + se->dobj.type = SND_SOC_DOBJ_ENUM; + se->dobj.ops = tplg->ops; + INIT_LIST_HEAD(&se->dobj.list);
- switch (le32_to_cpu(ec->hdr.ops.info)) { - case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: - case SND_SOC_TPLG_CTL_ENUM_VALUE: - err = soc_tplg_denum_create_values(tplg, se, ec); - if (err < 0) { - dev_err(tplg->dev, - "ASoC: could not create values for %s\n", - ec->hdr.name); - goto err_denum; - } - fallthrough; - case SND_SOC_TPLG_CTL_ENUM: - case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: - case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: - err = soc_tplg_denum_create_texts(tplg, se, ec); - if (err < 0) { - dev_err(tplg->dev, - "ASoC: could not create texts for %s\n", - ec->hdr.name); - goto err_denum; - } - break; - default: - err = -EINVAL; + switch (le32_to_cpu(ec->hdr.ops.info)) { + case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: + case SND_SOC_TPLG_CTL_ENUM_VALUE: + ret = soc_tplg_denum_create_values(tplg, se, ec); + if (ret < 0) { dev_err(tplg->dev, - "ASoC: invalid enum control type %d for %s\n", - ec->hdr.ops.info, ec->hdr.name); - goto err_denum; - } - - /* map io handlers */ - err = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, tplg); - if (err) { - soc_control_err(tplg, &ec->hdr, ec->hdr.name); - goto err_denum; - } - - /* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, &kc, - (struct snd_soc_tplg_ctl_hdr *) ec); - if (err < 0) { - dev_err(tplg->dev, "ASoC: failed to init %s\n", + "ASoC: could not create values for %s\n", ec->hdr.name); - goto err_denum; + goto err; } - - /* register control here */ - err = soc_tplg_add_kcontrol(tplg, - &kc, &se->dobj.control.kcontrol); - if (err < 0) { - dev_err(tplg->dev, "ASoC: could not add kcontrol %s\n", + fallthrough; + case SND_SOC_TPLG_CTL_ENUM: + case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: + case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: + ret = soc_tplg_denum_create_texts(tplg, se, ec); + if (ret < 0) { + dev_err(tplg->dev, + "ASoC: could not create texts for %s\n", ec->hdr.name); - goto err_denum; + goto err; } + break; + default: + ret = -EINVAL; + dev_err(tplg->dev, + "ASoC: invalid enum control type %d for %s\n", + ec->hdr.ops.info, ec->hdr.name); + goto err; + }
- list_add(&se->dobj.list, &tplg->comp->dobj_list); + /* map io handlers */ + ret = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, tplg); + if (ret) { + soc_control_err(tplg, &ec->hdr, ec->hdr.name); + goto err; } - return 0;
-err_denum: - return err; + /* pass control to driver for optional further init */ + ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)ec); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: failed to init %s\n", ec->hdr.name); + goto err; + } + + /* register control here */ + ret = soc_tplg_add_kcontrol(tplg, &kc, &se->dobj.control.kcontrol); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: could not add kcontrol %s\n", ec->hdr.name); + goto err; + } + + list_add(&se->dobj.list, &tplg->comp->dobj_list); + +err: + return ret; }
static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg, @@ -1049,20 +1021,17 @@ static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg, case SND_SOC_TPLG_CTL_RANGE: case SND_SOC_TPLG_DAPM_CTL_VOLSW: case SND_SOC_TPLG_DAPM_CTL_PIN: - ret = soc_tplg_dmixer_create(tplg, 1, - le32_to_cpu(hdr->payload_size)); + ret = soc_tplg_dmixer_create(tplg, le32_to_cpu(hdr->payload_size)); break; case SND_SOC_TPLG_CTL_ENUM: case SND_SOC_TPLG_CTL_ENUM_VALUE: case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: - ret = soc_tplg_denum_create(tplg, 1, - le32_to_cpu(hdr->payload_size)); + ret = soc_tplg_denum_create(tplg, le32_to_cpu(hdr->payload_size)); break; case SND_SOC_TPLG_CTL_BYTES: - ret = soc_tplg_dbytes_create(tplg, 1, - le32_to_cpu(hdr->payload_size)); + ret = soc_tplg_dbytes_create(tplg, le32_to_cpu(hdr->payload_size)); break; default: soc_bind_err(tplg, control_hdr, i);
In practice soc_tplg_is_eof() returns boolean value and caller uses the return value in such way, so convert the function to really do it.
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index f5446aac8ac6..f8e482d616fb 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -104,13 +104,13 @@ static int soc_tplg_check_elem_count(struct soc_tplg *tplg, size_t elem_size, return 0; }
-static inline int soc_tplg_is_eof(struct soc_tplg *tplg) +static inline bool soc_tplg_is_eof(struct soc_tplg *tplg) { const u8 *end = tplg->hdr_pos;
if (end >= tplg->fw->data + tplg->fw->size) - return 1; - return 0; + return true; + return false; }
static inline unsigned long soc_tplg_get_hdr_offset(struct soc_tplg *tplg)
Name of SOC_TPLG_PASS_MIXER pass is bit confusing, suggesting that it may only apply to mixers. As it is used for all control types, change name to SOC_TPLG_PASS_CONTROL.
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index f8e482d616fb..4e7dabcd69a4 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -40,7 +40,7 @@ */ #define SOC_TPLG_PASS_MANIFEST 0 #define SOC_TPLG_PASS_VENDOR 1 -#define SOC_TPLG_PASS_MIXER 2 +#define SOC_TPLG_PASS_CONTROL 2 #define SOC_TPLG_PASS_WIDGET 3 #define SOC_TPLG_PASS_PCM_DAI 4 #define SOC_TPLG_PASS_GRAPH 5 @@ -360,7 +360,7 @@ static void remove_mixer(struct snd_soc_component *comp, { struct snd_card *card = comp->card->snd_card;
- if (pass != SOC_TPLG_PASS_MIXER) + if (pass != SOC_TPLG_PASS_CONTROL) return;
if (dobj->ops && dobj->ops->control_unload) @@ -376,7 +376,7 @@ static void remove_enum(struct snd_soc_component *comp, { struct snd_card *card = comp->card->snd_card;
- if (pass != SOC_TPLG_PASS_MIXER) + if (pass != SOC_TPLG_PASS_CONTROL) return;
if (dobj->ops && dobj->ops->control_unload) @@ -392,7 +392,7 @@ static void remove_bytes(struct snd_soc_component *comp, { struct snd_card *card = comp->card->snd_card;
- if (pass != SOC_TPLG_PASS_MIXER) + if (pass != SOC_TPLG_PASS_CONTROL) return;
if (dobj->ops && dobj->ops->control_unload) @@ -2467,7 +2467,7 @@ static int soc_tplg_load_header(struct soc_tplg *tplg, case SND_SOC_TPLG_TYPE_MIXER: case SND_SOC_TPLG_TYPE_ENUM: case SND_SOC_TPLG_TYPE_BYTES: - hdr_pass = SOC_TPLG_PASS_MIXER; + hdr_pass = SOC_TPLG_PASS_CONTROL; elem_load = soc_tplg_kcontrol_elems_load; break; case SND_SOC_TPLG_TYPE_DAPM_GRAPH:
Error message refers to mixer, but it is used for various other types of controls, so change it to refer to generic "controls".
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 4e7dabcd69a4..3390bf0f8295 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -237,7 +237,7 @@ static inline void soc_control_err(struct soc_tplg *tplg, struct snd_soc_tplg_ctl_hdr *hdr, const char *name) { dev_err(tplg->dev, - "ASoC: no complete mixer IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n", + "ASoC: no complete control IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n", name, hdr->ops.get, hdr->ops.put, hdr->ops.info, soc_tplg_get_offset(tplg)); }
Other functions used for callbacks are named after function they call, however function calling control_load seems to be an exception. Rename it to soc_tplg_control_load().
Signed-off-by: Amadeusz Sławiński amadeuszx.slawinski@linux.intel.com --- sound/soc/soc-topology.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 3390bf0f8295..ddbc05306a8f 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -618,7 +618,7 @@ int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_bind_event);
/* optionally pass new dynamic kcontrol to component driver. */ -static int soc_tplg_init_kcontrol(struct soc_tplg *tplg, +static int soc_tplg_control_load(struct soc_tplg *tplg, struct snd_kcontrol_new *k, struct snd_soc_tplg_ctl_hdr *hdr) { if (tplg->ops && tplg->ops->control_load) @@ -725,7 +725,7 @@ static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size) }
/* pass control to driver for optional further init */ - ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)be); + ret = soc_tplg_control_load(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)be); if (ret < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", be->hdr.name); goto err; @@ -809,7 +809,7 @@ static int soc_tplg_dmixer_create(struct soc_tplg *tplg, size_t size) }
/* pass control to driver for optional further init */ - ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)mc); + ret = soc_tplg_control_load(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)mc); if (ret < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", mc->hdr.name); goto err; @@ -977,7 +977,7 @@ static int soc_tplg_denum_create(struct soc_tplg *tplg, size_t size) }
/* pass control to driver for optional further init */ - ret = soc_tplg_init_kcontrol(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)ec); + ret = soc_tplg_control_load(tplg, &kc, (struct snd_soc_tplg_ctl_hdr *)ec); if (ret < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", ec->hdr.name); goto err; @@ -1193,8 +1193,7 @@ static int soc_tplg_dapm_widget_dmixer_create(struct soc_tplg *tplg, struct snd_ }
/* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, kc, - (struct snd_soc_tplg_ctl_hdr *)mc); + err = soc_tplg_control_load(tplg, kc, (struct snd_soc_tplg_ctl_hdr *)mc); if (err < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", mc->hdr.name); @@ -1278,8 +1277,7 @@ static int soc_tplg_dapm_widget_denum_create(struct soc_tplg *tplg, struct snd_k }
/* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, kc, - (struct snd_soc_tplg_ctl_hdr *)ec); + err = soc_tplg_control_load(tplg, kc, (struct snd_soc_tplg_ctl_hdr *)ec); if (err < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", ec->hdr.name); @@ -1331,8 +1329,7 @@ static int soc_tplg_dapm_widget_dbytes_create(struct soc_tplg *tplg, struct snd_ }
/* pass control to driver for optional further init */ - err = soc_tplg_init_kcontrol(tplg, kc, - (struct snd_soc_tplg_ctl_hdr *)be); + err = soc_tplg_control_load(tplg, kc, (struct snd_soc_tplg_ctl_hdr *)be); if (err < 0) { dev_err(tplg->dev, "ASoC: failed to init %s\n", be->hdr.name);
On 2022-04-01 2:01 PM, Amadeusz Sławiński wrote:
Following patches contain minor changes, cleaning up code to be easier to read. Clean up few loops, to be simpler or altogether remove them. Rename some things to make code easier to understand.
While avs-driver is not fully upstreamed yet, I believe it is still vital to state that patches have been tested on following cAVS 1.5 platforms i.e.: Skylake, Kabylake, Amberlake, Appololake and their variants with the avs-drivers.
As code looks good to me:
Reviewed-by: Cezary Rojewski cezary.rojewski@intel.com
Amadeusz Sławiński (6): ASoC: topology: Use for loop instead of while ASoC: topology: Remove unnecessary looping ASoC: topology: Return bool instead of int ASoC: topology: Rename SOC_TPLG_PASS_MIXER to _CONTROL ASoC: topology: Correct error message ASoC: topology: Rename soc_tplg_init_kcontrol() function
sound/soc/soc-topology.c | 455 ++++++++++++++++++--------------------- 1 file changed, 208 insertions(+), 247 deletions(-)
On Fri, 2022-04-01 at 14:01 +0200, Amadeusz Sławiński wrote:
Following patches contain minor changes, cleaning up code to be easier to read. Clean up few loops, to be simpler or altogether remove them. Rename some things to make code easier to understand.
Amadeusz Sławiński (6): ASoC: topology: Use for loop instead of while ASoC: topology: Remove unnecessary looping ASoC: topology: Return bool instead of int ASoC: topology: Rename SOC_TPLG_PASS_MIXER to _CONTROL ASoC: topology: Correct error message ASoC: topology: Rename soc_tplg_init_kcontrol() function
sound/soc/soc-topology.c | 455 ++++++++++++++++++-------------------
1 file changed, 208 insertions(+), 247 deletions(-)
Looks good to me. Thanks!
Reviewed-by: Ranjani Sridharan ranjani.sridharan@linux.intel.com
On Fri, 1 Apr 2022 14:01:54 +0200, Amadeusz Sławiński wrote:
Following patches contain minor changes, cleaning up code to be easier to read. Clean up few loops, to be simpler or altogether remove them. Rename some things to make code easier to understand.
Amadeusz Sławiński (6): ASoC: topology: Use for loop instead of while ASoC: topology: Remove unnecessary looping ASoC: topology: Return bool instead of int ASoC: topology: Rename SOC_TPLG_PASS_MIXER to _CONTROL ASoC: topology: Correct error message ASoC: topology: Rename soc_tplg_init_kcontrol() function
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/6] ASoC: topology: Use for loop instead of while commit: 395f8fd616086310c40ddc4e9686440f147d5c00 [2/6] ASoC: topology: Remove unnecessary looping commit: 0db627c4f5df704d44699ed27dd81caa6d782a17 [3/6] ASoC: topology: Return bool instead of int commit: 4fad3cc6eb962a6fe32ab9fb9d30b08a88298f63 [4/6] ASoC: topology: Rename SOC_TPLG_PASS_MIXER to _CONTROL commit: 5e2cd47a36b386080e7a29c1efbb0247ed6ed365 [5/6] ASoC: topology: Correct error message commit: 34b310451cbf4dedcee56b4534085c20203c6b53 [6/6] ASoC: topology: Rename soc_tplg_init_kcontrol() function commit: 430791dd9207271099002b65aa65fd5e6aa31236
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
participants (4)
-
Amadeusz Sławiński
-
Cezary Rojewski
-
Mark Brown
-
Ranjani Sridharan