Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: omap - convert reqctx buffer to fixed-size array

The flexible array member 'buffer' in 'omap_sham_reqctx' is always
allocated with BUFLEN bytes. Replace the flexible array with a
fixed-size array and remove the now-redundant 'buflen' field.

Since 'struct omap_sham_reqctx' now includes the buffer, simplify
'reqsize' and 'statesize' and use an offsetof-based memcpy() in
omap_sham_export() and omap_sham_import().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Thorsten Blum and committed by
Herbert Xu
809c9b60 a883b38a

+10 -11
+10 -11
drivers/crypto/omap-sham.c
··· 147 147 u8 digest[SHA512_DIGEST_SIZE] OMAP_ALIGNED; 148 148 size_t digcnt; 149 149 size_t bufcnt; 150 - size_t buflen; 151 150 152 151 /* walk state */ 153 152 struct scatterlist *sg; ··· 155 156 int sg_len; 156 157 unsigned int total; /* total request */ 157 158 158 - u8 buffer[] OMAP_ALIGNED; 159 + u8 buffer[BUFLEN] OMAP_ALIGNED; 159 160 }; 160 161 161 162 struct omap_sham_hmac_ctx { ··· 890 891 if (hash_later < 0) 891 892 hash_later = 0; 892 893 893 - if (hash_later && hash_later <= rctx->buflen) { 894 + if (hash_later && hash_later <= sizeof(rctx->buffer)) { 894 895 scatterwalk_map_and_copy(rctx->buffer, 895 896 req->src, 896 897 req->nbytes - hash_later, ··· 901 902 rctx->bufcnt = 0; 902 903 } 903 904 904 - if (hash_later > rctx->buflen) 905 + if (hash_later > sizeof(rctx->buffer)) 905 906 set_bit(FLAGS_HUGE, &rctx->dd->flags); 906 907 907 908 rctx->total = min(nbytes, rctx->total); ··· 986 987 ctx->digcnt = 0; 987 988 ctx->total = 0; 988 989 ctx->offset = 0; 989 - ctx->buflen = BUFLEN; 990 990 991 991 if (tctx->flags & BIT(FLAGS_HMAC)) { 992 992 if (!test_bit(FLAGS_AUTO_XOR, &dd->flags)) { ··· 1198 1200 if (!req->nbytes) 1199 1201 return 0; 1200 1202 1201 - if (ctx->bufcnt + req->nbytes <= ctx->buflen) { 1203 + if (ctx->bufcnt + req->nbytes <= sizeof(ctx->buffer)) { 1202 1204 scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src, 1203 1205 0, req->nbytes, 0); 1204 1206 ctx->bufcnt += req->nbytes; ··· 1331 1333 } 1332 1334 1333 1335 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), 1334 - sizeof(struct omap_sham_reqctx) + BUFLEN); 1336 + sizeof(struct omap_sham_reqctx)); 1335 1337 1336 1338 if (alg_base) { 1337 1339 struct omap_sham_hmac_ctx *bctx = tctx->base; ··· 1402 1404 { 1403 1405 struct omap_sham_reqctx *rctx = ahash_request_ctx(req); 1404 1406 1405 - memcpy(out, rctx, sizeof(*rctx) + rctx->bufcnt); 1407 + memcpy(out, rctx, offsetof(struct omap_sham_reqctx, buffer) + 1408 + rctx->bufcnt); 1406 1409 1407 1410 return 0; 1408 1411 } ··· 1413 1414 struct omap_sham_reqctx *rctx = ahash_request_ctx(req); 1414 1415 const struct omap_sham_reqctx *ctx_in = in; 1415 1416 1416 - memcpy(rctx, in, sizeof(*rctx) + ctx_in->bufcnt); 1417 + memcpy(rctx, in, offsetof(struct omap_sham_reqctx, buffer) + 1418 + ctx_in->bufcnt); 1417 1419 1418 1420 return 0; 1419 1421 } ··· 2146 2146 alg = &ealg->base; 2147 2147 alg->export = omap_sham_export; 2148 2148 alg->import = omap_sham_import; 2149 - alg->halg.statesize = sizeof(struct omap_sham_reqctx) + 2150 - BUFLEN; 2149 + alg->halg.statesize = sizeof(struct omap_sham_reqctx); 2151 2150 err = crypto_engine_register_ahash(ealg); 2152 2151 if (err) 2153 2152 goto err_algs;