crypto: ccree - reduce kernel stack usage with clang
authorArnd Bergmann <arnd@arndb.de>
Thu, 14 Mar 2019 09:09:44 +0000 (10:09 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 Mar 2019 12:57:28 +0000 (20:57 +0800)
Building with clang for a 32-bit architecture runs over the stack
frame limit in the setkey function:

drivers/crypto/ccree/cc_cipher.c:318:12: error: stack frame size of 1152 bytes in function 'cc_cipher_setkey' [-Werror,-Wframe-larger-than=]

The problem is that there are two large variables: the temporary
'tmp' array and the SHASH_DESC_ON_STACK() declaration. Moving
the first into the block in which it is used reduces the
total frame size to 768 bytes, which seems more reasonable
and is under the warning limit.

Fixes: 63ee04c8b491 ("crypto: ccree - add skcipher support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-By: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccree/cc_cipher.c

index d9c17078517bddbb5d7d13599f1660b32a1a55a8..0abcdc224ab0a0d8edbd1cd90a9324d7b18292b7 100644 (file)
@@ -321,7 +321,6 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
        struct crypto_tfm *tfm = crypto_skcipher_tfm(sktfm);
        struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
        struct device *dev = drvdata_to_dev(ctx_p->drvdata);
-       u32 tmp[DES3_EDE_EXPKEY_WORDS];
        struct cc_crypto_alg *cc_alg =
                        container_of(tfm->__crt_alg, struct cc_crypto_alg,
                                     skcipher_alg.base);
@@ -347,6 +346,7 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
         * HW does the expansion on its own.
         */
        if (ctx_p->flow_mode == S_DIN_to_DES) {
+               u32 tmp[DES3_EDE_EXPKEY_WORDS];
                if (keylen == DES3_EDE_KEY_SIZE &&
                    __des3_ede_setkey(tmp, &tfm->crt_flags, key,
                                      DES3_EDE_KEY_SIZE)) {