diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-05-26 14:40:14 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-05-26 16:21:57 +0100 |
commit | d6b6c2ca6a2fbbb39051ec1d2763a947e3283683 (patch) | |
tree | 574dd1490eda7fc297798d48a1f895876b129dde /sound/soc/soc-core.c | |
parent | 9e4980896c46ed84d0aa27382e18d1cacb7cb86e (diff) | |
download | op-kernel-dev-d6b6c2ca6a2fbbb39051ec1d2763a947e3283683.zip op-kernel-dev-d6b6c2ca6a2fbbb39051ec1d2763a947e3283683.tar.gz |
ASoC: Simplify format_register_str() without stack usages
Instead of allocating two string buffers on stack and copying them
back, manipulate directly the target string buffer. This simplifies
the code well.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r-- | sound/soc/soc-core.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 7d028e8..95414a2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -92,30 +92,21 @@ static int format_register_str(struct snd_soc_codec *codec, int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; int regsize = codec->driver->reg_word_size * 2; int ret; - char tmpbuf[len + 1]; - char regbuf[regsize + 1]; - - /* since tmpbuf is allocated on the stack, warn the callers if they - * try to abuse this function */ - WARN_ON(len > 63); /* +2 for ': ' and + 1 for '\n' */ if (wordsize + regsize + 2 + 1 != len) return -EINVAL; - ret = snd_soc_read(codec, reg); - if (ret < 0) { - memset(regbuf, 'X', regsize); - regbuf[regsize] = '\0'; - } else { - snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); - } - - /* prepare the buffer */ - snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); - /* copy it back to the caller without the '\0' */ - memcpy(buf, tmpbuf, len); + sprintf(buf, "%.*x: ", wordsize, reg); + buf += wordsize + 2; + ret = snd_soc_read(codec, reg); + if (ret < 0) + memset(buf, 'X', regsize); + else + sprintf(buf, "%.*x", regsize, ret); + buf[regsize] = '\n'; + /* no NUL-termination needed */ return 0; } |