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] ASoC: core: Only kmemdup binary control buffer if masking
Date: Wed, 2 Apr 2014 15:17:05 +0100 [thread overview]
Message-ID: <1396448225-19936-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> (raw)
When writing a binary control we may apply a mask to the first register,
as this requires modifying the data the buffer is duplicated, currently
this is done for all binary control writes. As most binary controls
don't use the mask facility and thus can freely use the original buffer,
avoid the kmemdup for these cases.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
sound/soc/soc-core.c | 86 ++++++++++++++++++++++++-------------------------
1 files changed, 42 insertions(+), 44 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index caebd63..275bd71 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3229,67 +3229,65 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
len = params->num_regs * codec->val_bytes;
- data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
- if (!data)
- return -ENOMEM;
+ if (!params->mask)
+ return regmap_raw_write(codec->control_data, params->base,
+ ucontrol->value.bytes.data, len);
/*
* If we've got a mask then we need to preserve the register
* bits. We shouldn't modify the incoming data so take a
* copy.
*/
- if (params->mask) {
- ret = regmap_read(codec->control_data, params->base, &val);
- if (ret != 0)
- goto out;
+ data = kmemdup(ucontrol->value.bytes.data, len,
+ GFP_KERNEL | GFP_DMA);
+ if (!data)
+ return -ENOMEM;
- val &= params->mask;
+ ret = regmap_read(codec->control_data, params->base, &val);
+ if (ret != 0)
+ goto out;
- switch (codec->val_bytes) {
- case 1:
- ((u8 *)data)[0] &= ~params->mask;
- ((u8 *)data)[0] |= val;
- break;
- case 2:
- mask = ~params->mask;
- ret = regmap_parse_val(codec->control_data,
- &mask, &mask);
- if (ret != 0)
- goto out;
+ val &= params->mask;
- ((u16 *)data)[0] &= mask;
+ switch (codec->val_bytes) {
+ case 1:
+ ((u8 *)data)[0] &= ~params->mask;
+ ((u8 *)data)[0] |= val;
+ break;
+ case 2:
+ mask = ~params->mask;
+ ret = regmap_parse_val(codec->control_data, &mask, &mask);
+ if (ret != 0)
+ goto out;
- ret = regmap_parse_val(codec->control_data,
- &val, &val);
- if (ret != 0)
- goto out;
+ ((u16 *)data)[0] &= mask;
- ((u16 *)data)[0] |= val;
- break;
- case 4:
- mask = ~params->mask;
- ret = regmap_parse_val(codec->control_data,
- &mask, &mask);
- if (ret != 0)
- goto out;
+ ret = regmap_parse_val(codec->control_data, &val, &val);
+ if (ret != 0)
+ goto out;
- ((u32 *)data)[0] &= mask;
+ ((u16 *)data)[0] |= val;
+ break;
+ case 4:
+ mask = ~params->mask;
+ ret = regmap_parse_val(codec->control_data, &mask, &mask);
+ if (ret != 0)
+ goto out;
- ret = regmap_parse_val(codec->control_data,
- &val, &val);
- if (ret != 0)
- goto out;
+ ((u32 *)data)[0] &= mask;
- ((u32 *)data)[0] |= val;
- break;
- default:
- ret = -EINVAL;
+ ret = regmap_parse_val(codec->control_data, &val, &val);
+ if (ret != 0)
goto out;
- }
+
+ ((u32 *)data)[0] |= val;
+ break;
+ default:
+ ret = -EINVAL;
+ goto out;
}
- ret = regmap_raw_write(codec->control_data, params->base,
- data, len);
+ ret = regmap_raw_write(codec->control_data, params->base, data, len);
out:
kfree(data);
--
1.7.2.5
next reply other threads:[~2014-04-02 14:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-02 14:17 Charles Keepax [this message]
2014-04-02 14:41 ` [PATCH] ASoC: core: Only kmemdup binary control buffer if masking Mark Brown
2014-04-02 14:49 ` Charles Keepax
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=1396448225-19936-1-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.