crypto: api - Add helpers to manage request flags
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 7 Apr 2025 10:02:51 +0000 (18:02 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 16 Apr 2025 07:16:20 +0000 (15:16 +0800)
Add helpers so that the ON_STACK request flag management is not
duplicated all over the place.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
include/crypto/algapi.h
include/linux/crypto.h

index ede622ecefa8e25bf4f3074c1af38b486ebf32fa..6999e10ea09e346a3d13b06ea42357d3d7af910e 100644 (file)
@@ -272,4 +272,9 @@ static inline bool crypto_tfm_req_chain(struct crypto_tfm *tfm)
        return tfm->__crt_alg->cra_flags & CRYPTO_ALG_REQ_CHAIN;
 }
 
+static inline u32 crypto_request_flags(struct crypto_async_request *req)
+{
+       return req->flags & ~CRYPTO_TFM_REQ_ON_STACK;
+}
+
 #endif /* _CRYPTO_ALGAPI_H */
index dd817f56ff0ca76eb6c343a7b4397c28f49bbf03..a387f1547ea0820eafd7e76f7b7893ee2851c9a7 100644 (file)
@@ -476,5 +476,29 @@ static inline bool crypto_tfm_is_async(struct crypto_tfm *tfm)
        return tfm->__crt_alg->cra_flags & CRYPTO_ALG_ASYNC;
 }
 
+static inline bool crypto_req_on_stack(struct crypto_async_request *req)
+{
+       return req->flags & CRYPTO_TFM_REQ_ON_STACK;
+}
+
+static inline void crypto_request_set_callback(
+       struct crypto_async_request *req, u32 flags,
+       crypto_completion_t compl, void *data)
+{
+       u32 keep = CRYPTO_TFM_REQ_ON_STACK;
+
+       req->complete = compl;
+       req->data = data;
+       req->flags &= keep;
+       req->flags |= flags & ~keep;
+}
+
+static inline void crypto_request_set_tfm(struct crypto_async_request *req,
+                                         struct crypto_tfm *tfm)
+{
+       req->tfm = tfm;
+       req->flags &= ~CRYPTO_TFM_REQ_ON_STACK;
+}
+
 #endif /* _LINUX_CRYPTO_H */