mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically
@ 2020-05-07 21:33 Arnd Bergmann
  2020-05-08 14:21 ` Tzung-Bi Shih
  2020-05-08 17:52 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2020-05-07 21:33 UTC (permalink / raw)
  To: Cheng-Yi Chiang, Mark Brown
  Cc: Arnd Bergmann, Tzung-Bi Shih, Enric Balletbo i Serra,
	Guenter Roeck, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Benson Leung, Yu-Hsuan Hsu, Kuninori Morimoto, alsa-devel,
	linux-kernel

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: b6bc07d4360d ("ASoC: cros_ec_codec: support WoV")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sound/soc/codecs/cros_ec_codec.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index d3dc42aa6825..1948bc6971f6 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -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
-- 
2.26.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically
  2020-05-07 21:33 [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically Arnd Bergmann
@ 2020-05-08 14:21 ` Tzung-Bi Shih
  2020-05-08 17:52 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2020-05-08 14:21 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Cheng-Yi Chiang, Mark Brown, Enric Balletbo i Serra,
	Guenter Roeck, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Benson Leung, Yu-Hsuan Hsu, Kuninori Morimoto, ALSA development,
	Linux Kernel Mailing List

On Fri, May 8, 2020 at 5:34 AM Arnd Bergmann <arnd@arndb.de> wrote:
> Fixes: b6bc07d4360d ("ASoC: cros_ec_codec: support WoV")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>

LGTM.  Thanks for the fix.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically
  2020-05-07 21:33 [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically Arnd Bergmann
  2020-05-08 14:21 ` Tzung-Bi Shih
@ 2020-05-08 17:52 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-05-08 17:52 UTC (permalink / raw)
  To: Arnd Bergmann, Cheng-Yi Chiang
  Cc: Enric Balletbo i Serra, Guenter Roeck, linux-kernel,
	Liam Girdwood, Benson Leung, alsa-devel, Takashi Iwai,
	Yu-Hsuan Hsu, Tzung-Bi Shih, Kuninori Morimoto

On Thu, 7 May 2020 23:33:51 +0200, Arnd Bergmann wrote:
> 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.

Applied to

   local tree asoc/for-5.7

Thanks!

[1/1] ASoC: cros_ec_codec: allocate shash_desc dynamically
      (no commit info)

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-08 17:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 21:33 [PATCH] ASoC: cros_ec_codec: allocate shash_desc dynamically Arnd Bergmann
2020-05-08 14:21 ` Tzung-Bi Shih
2020-05-08 17:52 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®