diff mbox series

[11/13] ASoC: topology: Unify code for creating standalone and widget bytes control

Message ID 20240627101850.2191513-12-amadeuszx.slawinski@linux.intel.com (mailing list archive)
State Accepted
Commit 0867278200f787817036419fc87b56fb04a448e4
Headers show
Series ASoC: topology: kcontrol registration cleanup | expand

Commit Message

Amadeusz Sławiński June 27, 2024, 10:18 a.m. UTC
Code used to create standalone and widget bytes control is same, with
exception that in standalone case dynamic object needs to be registered
and control created directly.

Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
---
 sound/soc/soc-topology.c | 51 +++++++---------------------------------
 1 file changed, 9 insertions(+), 42 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 5aab1df7e2606..b10a6be8f75b3 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -875,41 +875,21 @@  static int soc_tplg_control_dbytes_create(struct soc_tplg *tplg, struct snd_kcon
 
 static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size)
 {
-	struct snd_soc_tplg_bytes_control *be;
+	struct snd_kcontrol_new kc = {0};
 	struct soc_bytes_ext *sbe;
-	struct snd_kcontrol_new kc;
-	int ret = 0;
+	int ret;
 
 	if (soc_tplg_check_elem_count(tplg,
 				      sizeof(struct snd_soc_tplg_bytes_control),
 				      1, size, "mixer bytes"))
 		return -EINVAL;
 
-	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;
-
-	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));
-
-	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);
+	ret = soc_tplg_control_dbytes_create(tplg, &kc);
+	if (ret)
+		return ret;
 
-	sbe->max = le32_to_cpu(be->max);
+	/* register dynamic object */
+	sbe = (struct soc_bytes_ext *)&kc.private_value;
 
 	INIT_LIST_HEAD(&sbe->dobj.list);
 	sbe->dobj.type = SND_SOC_DOBJ_BYTES;
@@ -917,26 +897,13 @@  static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size)
 	if (tplg->ops)
 		sbe->dobj.unload = tplg->ops->control_unload;
 
-	/* 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;
-	}
-
-	/* pass control to driver for optional further init */
-	ret = soc_tplg_control_load(tplg, &kc, &be->hdr);
-	if (ret < 0)
-		goto err;
-
-	/* register control here */
+	/* create control directly */
 	ret = soc_tplg_add_kcontrol(tplg, &kc, &sbe->dobj.control.kcontrol);
 	if (ret < 0)
-		goto err;
+		return ret;
 
 	list_add(&sbe->dobj.list, &tplg->comp->dobj_list);
 
-err:
 	return ret;
 }