All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
To: broonie@kernel.org
Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	lgirdwood@gmail.com
Subject: [PATCH 05/13] ASoC: wm_adsp: Move temporary control name to the stack
Date: Mon, 13 Apr 2015 13:27:57 +0100	[thread overview]
Message-ID: <1428928085-20250-6-git-send-email-ckeepax@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1428928085-20250-1-git-send-email-ckeepax@opensource.wolfsonmicro.com>

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: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
 sound/soc/codecs/wm_adsp.c |   23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index c291203..6c4f013 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -785,14 +785,10 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
 {
 	struct wm_coeff_ctl *ctl;
 	struct wmfw_ctl_work *ctl_work;
-	char *name;
+	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
 	char *region_name;
 	int ret;
 
-	name = kmalloc(SNDRV_CTL_ELEM_ID_NAME_MAXLEN, GFP_KERNEL);
-	if (!name)
-		return -ENOMEM;
-
 	switch (alg_region->type) {
 	case WMFW_ADSP1_PM:
 		region_name = "PM";
@@ -810,8 +806,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
 		region_name = "ZM";
 		break;
 	default:
-		ret = -EINVAL;
-		goto err_name;
+		return -EINVAL;
 	}
 
 	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 (!ctl->enabled)
 				ctl->enabled = 1;
-			goto found;
+			return 0;
 		}
 	}
 
 	ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
-	if (!ctl) {
-		ret = -ENOMEM;
-		goto err_name;
-	}
+	if (!ctl)
+		return -ENOMEM;
 	ctl->alg_region = *alg_region;
 	ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
 	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);
 	schedule_work(&ctl_work->work);
 
-found:
-	kfree(name);
-
 	return 0;
 
 err_ctl_cache:
@@ -877,8 +867,7 @@ err_ctl_name:
 	kfree(ctl->name);
 err_ctl:
 	kfree(ctl);
-err_name:
-	kfree(name);
+
 	return ret;
 }
 
-- 
1.7.2.5

  parent reply	other threads:[~2015-04-13 12:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 12:27 [PATCH 00/13] ADSP Firmware Controls Update Charles Keepax
2015-04-13 12:27 ` [PATCH 01/13] ASoC: wm_adsp: Split out adsp1 & 2 setup algorithms Charles Keepax
2015-04-13 12:27 ` [PATCH 02/13] ASoC: wm_adsp: Improve variable naming Charles Keepax
2015-04-13 12:27 ` [PATCH 03/13] ASoC: wm_adsp: Remove len field from wm_adsp_alg_region Charles Keepax
2015-04-13 12:27 ` [PATCH 04/13] ASoC: wm_adsp: Limit firmware control name to ALSA control name size Charles Keepax
2015-04-13 12:27 ` Charles Keepax [this message]
2015-04-13 12:27 ` [PATCH 06/13] ASoC: wm_adsp: Clean up low level control read/write functions Charles Keepax
2015-04-13 12:27 ` [PATCH 07/13] ASoC: wm_adsp: Factor out creation of alg_regions Charles Keepax
2015-04-13 12:28 ` [PATCH 08/13] ASoC: wm_adsp: Remove private field from wm_coeff_ctl Charles Keepax
2015-04-13 12:28 ` [PATCH 09/13] ASoC: wm_adsp: Group all the ALSA control functions together Charles Keepax
2015-04-13 12:28 ` [PATCH 10/13] ASoC: wm_adsp: Add basic support for rev 1 firmware file format Charles Keepax
2015-04-18 17:26   ` Mark Brown
2015-04-13 12:28 ` [PATCH 11/13] ASoC: wm_adsp: Add support for DSP control flags Charles Keepax
2015-04-18 17:23   ` Mark Brown
2015-04-20  8:30     ` Charles Keepax
2015-04-13 12:28 ` [PATCH 12/13] ASoC: wm_adsp: Add support for rev 2 firmware file format Charles Keepax
2015-04-18 17:26   ` Mark Brown
2015-04-13 12:28 ` [PATCH 13/13] ASoC: wm_adsp: Warn that firmware file format 0 is depreciated Charles Keepax
2015-04-18 17:26   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428928085-20250-6-git-send-email-ckeepax@opensource.wolfsonmicro.com \
    --to=ckeepax@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=patches@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.