crypto: api - Add crypto_stack_request_init and initialise flags fully
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 25 Apr 2025 03:05:29 +0000 (11:05 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 28 Apr 2025 11:45:26 +0000 (19:45 +0800)
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 <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202504250751.mdy28Ibr-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
include/crypto/acompress.h
include/crypto/hash.h
include/crypto/internal/acompress.h
include/crypto/internal/hash.h
include/linux/crypto.h

index 933c48a4855bcae0977a457b5193e3f2b012d8b7..f1812e92d3e338d6a8957a0fdeae69b8b4a584a4 100644 (file)
@@ -547,8 +547,7 @@ static inline struct acomp_req *acomp_request_on_stack_init(
 {
        struct acomp_req *req = (void *)buf;
 
-       acomp_request_set_tfm(req, tfm);
-       req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
+       crypto_stack_request_init(&req->base, crypto_acomp_tfm(tfm));
        return req;
 }
 
index 68813a83443bcd21cf2990440f21a47fd7159189..c2497c300a28846e120839e2b62734f4664117ad 100644 (file)
@@ -1029,8 +1029,7 @@ static inline struct ahash_request *ahash_request_on_stack_init(
 {
        struct ahash_request *req = (void *)buf;
 
-       ahash_request_set_tfm(req, tfm);
-       req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
+       crypto_stack_request_init(&req->base, crypto_ahash_tfm(tfm));
        return req;
 }
 
index 6550dad18e0fbbd7bdcf3b058c6cdc0f54ce1b54..b72bb7a6a2b242e72d98d46a1fb2246269e5fd74 100644 (file)
@@ -231,8 +231,8 @@ static inline struct acomp_req *acomp_fbreq_on_stack_init(
        struct crypto_acomp *tfm = crypto_acomp_reqtfm(old);
        struct acomp_req *req = (void *)buf;
 
-       acomp_request_set_tfm(req, crypto_acomp_fb(tfm));
-       req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
+       crypto_stack_request_init(&req->base,
+                                 crypto_acomp_tfm(crypto_acomp_fb(tfm)));
        acomp_request_set_callback(req, acomp_request_flags(old), NULL, NULL);
        req->base.flags &= ~CRYPTO_ACOMP_REQ_PRIVATE;
        req->base.flags |= old->base.flags & CRYPTO_ACOMP_REQ_PRIVATE;
index 0bc0fefc9b3c7384828abd1016addae53f86d88c..33d45275f5bd454282c70cb23ded250340ea2a23 100644 (file)
@@ -283,8 +283,8 @@ static inline struct ahash_request *ahash_fbreq_on_stack_init(
        struct crypto_ahash *tfm = crypto_ahash_reqtfm(old);
        struct ahash_request *req = (void *)buf;
 
-       ahash_request_set_tfm(req, crypto_ahash_fb(tfm));
-       req->base.flags = CRYPTO_TFM_REQ_ON_STACK;
+       crypto_stack_request_init(&req->base,
+                                 crypto_ahash_tfm(crypto_ahash_fb(tfm)));
        ahash_request_set_callback(req, ahash_request_flags(old), NULL, NULL);
        req->base.flags &= ~CRYPTO_AHASH_REQ_PRIVATE;
        req->base.flags |= old->base.flags & CRYPTO_AHASH_REQ_PRIVATE;
index fe75320ff9a35c5be28395538b97ecc55e839fc6..b8d875b11193d687e37683fd17622884dc2ee845 100644 (file)
@@ -514,5 +514,13 @@ static inline void crypto_request_set_tfm(struct crypto_async_request *req,
 struct crypto_async_request *crypto_request_clone(
        struct crypto_async_request *req, size_t total, gfp_t gfp);
 
+static inline void crypto_stack_request_init(struct crypto_async_request *req,
+                                            struct crypto_tfm *tfm)
+{
+       req->flags = 0;
+       crypto_request_set_tfm(req, tfm);
+       req->flags |= CRYPTO_TFM_REQ_ON_STACK;
+}
+
 #endif /* _LINUX_CRYPTO_H */