Skip to content

Commit 9d4cafa

Browse files
ebiggersherbertx
authored andcommitted
ASoC: cros_ec_codec: use sha256() instead of open coding
Now that there's a function that calculates the SHA-256 digest of a buffer in one step, use it instead of sha256_init() + sha256_update() + sha256_final(). Also simplify the code by inlining calculate_sha256() into its caller and switching a debug log statement to use %*phN instead of bin2hex(). Acked-by: Tzung-Bi Shih <tzungbi@google.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Cc: alsa-devel@alsa-project.org Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Cheng-Yi Chiang <cychiang@chromium.org> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com> Cc: Guenter Roeck <groeck@chromium.org> Cc: Tzung-Bi Shih <tzungbi@google.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5a7a0d9 commit 9d4cafa

1 file changed

Lines changed: 2 additions & 25 deletions

File tree

‎sound/soc/codecs/cros_ec_codec.c‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,6 @@ static int send_ec_host_command(struct cros_ec_device *ec_dev, uint32_t cmd,
103103
return ret;
104104
}
105105

106-
static int calculate_sha256(struct cros_ec_codec_priv *priv,
107-
uint8_t *buf, uint32_t size, uint8_t *digest)
108-
{
109-
struct sha256_state sctx;
110-
111-
sha256_init(&sctx);
112-
sha256_update(&sctx, buf, size);
113-
sha256_final(&sctx, digest);
114-
115-
#ifdef DEBUG
116-
{
117-
char digest_str[65];
118-
119-
bin2hex(digest_str, digest, 32);
120-
digest_str[64] = 0;
121-
dev_dbg(priv->dev, "hash=%s\n", digest_str);
122-
}
123-
#endif
124-
125-
return 0;
126-
}
127-
128106
static int dmic_get_gain(struct snd_kcontrol *kcontrol,
129107
struct snd_ctl_elem_value *ucontrol)
130108
{
@@ -782,9 +760,8 @@ static int wov_hotword_model_put(struct snd_kcontrol *kcontrol,
782760
if (IS_ERR(buf))
783761
return PTR_ERR(buf);
784762

785-
ret = calculate_sha256(priv, buf, size, digest);
786-
if (ret)
787-
goto leave;
763+
sha256(buf, size, digest);
764+
dev_dbg(priv->dev, "hash=%*phN\n", SHA256_DIGEST_SIZE, digest);
788765

789766
p.cmd = EC_CODEC_WOV_GET_LANG;
790767
ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,

0 commit comments

Comments
 (0)