mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
ASoC: cros_ec_codec: allocate shash_desc dynamically
The wov_hotword_model_put() function has multiple large variables on
its stack, the largest of which is the result of SHASH_DESC_ON_STACK().
In total, this exceeds the warning limit for 32-bit architectures:
sound/soc/codecs/cros_ec_codec.c:776:12: error: stack frame size of 1152 bytes in function 'wov_hotword_model_put' [-Werror,-Wframe-larger-than=]
The function already has a dynamic crypto_alloc_shash() allocation, so
using kmalloc() for the descriptor is correct as well and does not
introduce any additional failure scenarios. With this, the stack usage
of wov_hotword_model_put() gets reduced to 480 bytes in my test
configuration.
Fixes: b6bc07d436
("ASoC: cros_ec_codec: support WoV")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/r/20200507213405.1869430-1-arnd@arndb.de
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
2d6201ee11
commit
a1304cba81
@ -108,22 +108,23 @@ static int calculate_sha256(struct cros_ec_codec_priv *priv,
|
||||
uint8_t *buf, uint32_t size, uint8_t *digest)
|
||||
{
|
||||
struct crypto_shash *tfm;
|
||||
struct shash_desc *desc;
|
||||
|
||||
tfm = crypto_alloc_shash("sha256", CRYPTO_ALG_TYPE_SHASH, 0);
|
||||
if (IS_ERR(tfm)) {
|
||||
dev_err(priv->dev, "can't alloc shash\n");
|
||||
return PTR_ERR(tfm);
|
||||
}
|
||||
|
||||
{
|
||||
SHASH_DESC_ON_STACK(desc, tfm);
|
||||
|
||||
desc->tfm = tfm;
|
||||
|
||||
crypto_shash_digest(desc, buf, size, digest);
|
||||
shash_desc_zero(desc);
|
||||
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(tfm), GFP_KERNEL);
|
||||
if (!desc) {
|
||||
crypto_free_shash(tfm);
|
||||
return -ENOMEM;
|
||||
}
|
||||
desc->tfm = tfm;
|
||||
crypto_shash_digest(desc, buf, size, digest);
|
||||
shash_desc_zero(desc);
|
||||
|
||||
kfree(desc);
|
||||
crypto_free_shash(tfm);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user