diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2025-04-07 18:03:00 +0800 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2025-04-16 15:16:20 +0800 |
| commit | 097c432caaa6d91f87732fe991cb08139e31101a (patch) | |
| tree | cbf90c936c17accd824b0f16e4bc7210f6eb02ef /include/crypto/acompress.h | |
| parent | d0a5c9d079decad95a77638c19bc5b3a6a0ffe21 (diff) | |
crypto: acomp - Add ACOMP_REQUEST_CLONE
Add a new helper ACOMP_REQUEST_CLONE that will transform a stack
request into a dynamically allocated one if possible, and otherwise
switch it over to the sycnrhonous fallback transform. The intended
usage is:
ACOMP_STACK_ON_REQUEST(req, tfm);
...
err = crypto_acomp_compress(req);
/* The request cannot complete synchronously. */
if (err == -EAGAIN) {
/* This will not fail. */
req = ACOMP_REQUEST_CLONE(req, gfp);
/* Redo operation. */
err = crypto_acomp_compress(req);
}
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto/acompress.h')
| -rw-r--r-- | include/crypto/acompress.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index f383a4008854..93cee67c27c0 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -51,8 +51,17 @@ #define ACOMP_REQUEST_ALLOC(name, tfm, gfp) \ char __##name##_req[sizeof(struct acomp_req) + \ MAX_SYNC_COMP_REQSIZE] CRYPTO_MINALIGN_ATTR; \ + struct acomp_req *name = acomp_request_alloc_init( \ + __##name##_req, (tfm), (gfp)) + +#define ACOMP_REQUEST_ON_STACK(name, tfm) \ + char __##name##_req[sizeof(struct acomp_req) + \ + MAX_SYNC_COMP_REQSIZE] CRYPTO_MINALIGN_ATTR; \ struct acomp_req *name = acomp_request_on_stack_init( \ - __##name##_req, (tfm), (gfp), false) + __##name##_req, (tfm)) + +#define ACOMP_REQUEST_CLONE(name, gfp) \ + acomp_request_clone(name, sizeof(__##name##_req), gfp) struct acomp_req; struct folio; @@ -571,12 +580,12 @@ int crypto_acomp_compress(struct acomp_req *req); */ int crypto_acomp_decompress(struct acomp_req *req); -static inline struct acomp_req *acomp_request_on_stack_init( - char *buf, struct crypto_acomp *tfm, gfp_t gfp, bool stackonly) +static inline struct acomp_req *acomp_request_alloc_init( + char *buf, struct crypto_acomp *tfm, gfp_t gfp) { struct acomp_req *req; - if (!stackonly && (req = acomp_request_alloc(tfm, gfp))) + if ((req = acomp_request_alloc(tfm, gfp))) return req; req = (void *)buf; @@ -586,4 +595,17 @@ static inline struct acomp_req *acomp_request_on_stack_init( return req; } +static inline struct acomp_req *acomp_request_on_stack_init( + char *buf, struct crypto_acomp *tfm) +{ + struct acomp_req *req = (void *)buf; + + acomp_request_set_tfm(req, tfm); + req->base.flags = CRYPTO_TFM_REQ_ON_STACK; + return req; +} + +struct acomp_req *acomp_request_clone(struct acomp_req *req, + size_t total, gfp_t gfp); + #endif |