Skip to content

Commit b75fa20

Browse files
committed
crypto: api - Add crypto_stack_request_init and initialise flags fully
Add a helper to initialise crypto stack requests and use it for ahash and acomp. Make sure that the flags field is initialised fully in the helper to silence false-positive warnings from the compiler. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Herbert Xu <[email protected]>
1 parent e3b4965 commit b75fa20

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

include/crypto/acompress.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ static inline struct acomp_req *acomp_request_on_stack_init(
547547
{
548548
struct acomp_req *req = (void *)buf;
549549

550-
acomp_request_set_tfm(req, tfm);
551-
req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
550+
crypto_stack_request_init(&req->base, crypto_acomp_tfm(tfm));
552551
return req;
553552
}
554553

include/crypto/hash.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,7 @@ static inline struct ahash_request *ahash_request_on_stack_init(
10291029
{
10301030
struct ahash_request *req = (void *)buf;
10311031

1032-
ahash_request_set_tfm(req, tfm);
1033-
req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
1032+
crypto_stack_request_init(&req->base, crypto_ahash_tfm(tfm));
10341033
return req;
10351034
}
10361035

include/crypto/internal/acompress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ static inline struct acomp_req *acomp_fbreq_on_stack_init(
231231
struct crypto_acomp *tfm = crypto_acomp_reqtfm(old);
232232
struct acomp_req *req = (void *)buf;
233233

234-
acomp_request_set_tfm(req, crypto_acomp_fb(tfm));
235-
req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
234+
crypto_stack_request_init(&req->base,
235+
crypto_acomp_tfm(crypto_acomp_fb(tfm)));
236236
acomp_request_set_callback(req, acomp_request_flags(old), NULL, NULL);
237237
req->base.flags &= ~CRYPTO_ACOMP_REQ_PRIVATE;
238238
req->base.flags |= old->base.flags & CRYPTO_ACOMP_REQ_PRIVATE;

include/crypto/internal/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ static inline struct ahash_request *ahash_fbreq_on_stack_init(
283283
struct crypto_ahash *tfm = crypto_ahash_reqtfm(old);
284284
struct ahash_request *req = (void *)buf;
285285

286-
ahash_request_set_tfm(req, crypto_ahash_fb(tfm));
287-
req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
286+
crypto_stack_request_init(&req->base,
287+
crypto_ahash_tfm(crypto_ahash_fb(tfm)));
288288
ahash_request_set_callback(req, ahash_request_flags(old), NULL, NULL);
289289
req->base.flags &= ~CRYPTO_AHASH_REQ_PRIVATE;
290290
req->base.flags |= old->base.flags & CRYPTO_AHASH_REQ_PRIVATE;

include/linux/crypto.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,5 +514,13 @@ static inline void crypto_request_set_tfm(struct crypto_async_request *req,
514514
struct crypto_async_request *crypto_request_clone(
515515
struct crypto_async_request *req, size_t total, gfp_t gfp);
516516

517+
static inline void crypto_stack_request_init(struct crypto_async_request *req,
518+
struct crypto_tfm *tfm)
519+
{
520+
req->flags = 0;
521+
crypto_request_set_tfm(req, tfm);
522+
req->flags |= CRYPTO_TFM_REQ_ON_STACK;
523+
}
524+
517525
#endif /* _LINUX_CRYPTO_H */
518526

0 commit comments

Comments
 (0)