Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 512f2bba authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown
Browse files

ASoC: wm_adsp: Move temporary control name to the stack



Now we only allocate 44 bytes for the control name keep it on the stack
to avoid a lot of pointless memory allocation.

Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 0f4e918c
Loading
Loading
Loading
Loading
+6 −17
Original line number Original line Diff line number Diff line
@@ -785,14 +785,10 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
{
{
	struct wm_coeff_ctl *ctl;
	struct wm_coeff_ctl *ctl;
	struct wmfw_ctl_work *ctl_work;
	struct wmfw_ctl_work *ctl_work;
	char *name;
	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
	char *region_name;
	char *region_name;
	int ret;
	int ret;


	name = kmalloc(SNDRV_CTL_ELEM_ID_NAME_MAXLEN, GFP_KERNEL);
	if (!name)
		return -ENOMEM;

	switch (alg_region->type) {
	switch (alg_region->type) {
	case WMFW_ADSP1_PM:
	case WMFW_ADSP1_PM:
		region_name = "PM";
		region_name = "PM";
@@ -810,8 +806,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
		region_name = "ZM";
		region_name = "ZM";
		break;
		break;
	default:
	default:
		ret = -EINVAL;
		return -EINVAL;
		goto err_name;
	}
	}


	snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x",
	snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x",
@@ -822,15 +817,13 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
		if (!strcmp(ctl->name, name)) {
		if (!strcmp(ctl->name, name)) {
			if (!ctl->enabled)
			if (!ctl->enabled)
				ctl->enabled = 1;
				ctl->enabled = 1;
			goto found;
			return 0;
		}
		}
	}
	}


	ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
	ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
	if (!ctl) {
	if (!ctl)
		ret = -ENOMEM;
		return -ENOMEM;
		goto err_name;
	}
	ctl->alg_region = *alg_region;
	ctl->alg_region = *alg_region;
	ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
	ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
	if (!ctl->name) {
	if (!ctl->name) {
@@ -866,9 +859,6 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
	INIT_WORK(&ctl_work->work, wm_adsp_ctl_work);
	INIT_WORK(&ctl_work->work, wm_adsp_ctl_work);
	schedule_work(&ctl_work->work);
	schedule_work(&ctl_work->work);


found:
	kfree(name);

	return 0;
	return 0;


err_ctl_cache:
err_ctl_cache:
@@ -877,8 +867,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
	kfree(ctl->name);
	kfree(ctl->name);
err_ctl:
err_ctl:
	kfree(ctl);
	kfree(ctl);
err_name:

	kfree(name);
	return ret;
	return ret;
}
}