]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: acomp - Use request flag helpers and add acomp_request_flags
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 7 Apr 2025 10:02:53 +0000 (18:02 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 16 Apr 2025 07:16:20 +0000 (15:16 +0800)
Use the newly added request flag helpers to manage the request
flags.

Also add acomp_request_flags which lets bottom-level users to
access the request flags without the bits private to the acomp
API.

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

index 080e134df35cb1d35bfd0b4e3e27dd2f2e05e201..f383a400885419e1a8ee23012c7171c8c4365a36 100644 (file)
 /* Set this bit if destination is a folio. */
 #define CRYPTO_ACOMP_REQ_DST_FOLIO     0x00000040
 
+/* Private flags that should not be touched by the user. */
+#define CRYPTO_ACOMP_REQ_PRIVATE \
+       (CRYPTO_ACOMP_REQ_SRC_VIRT | CRYPTO_ACOMP_REQ_SRC_NONDMA | \
+        CRYPTO_ACOMP_REQ_DST_VIRT | CRYPTO_ACOMP_REQ_DST_NONDMA | \
+        CRYPTO_ACOMP_REQ_SRC_FOLIO | CRYPTO_ACOMP_REQ_DST_FOLIO)
+
 #define CRYPTO_ACOMP_DST_MAX           131072
 
 #define        MAX_SYNC_COMP_REQSIZE           0
@@ -201,7 +207,7 @@ static inline unsigned int crypto_acomp_reqsize(struct crypto_acomp *tfm)
 static inline void acomp_request_set_tfm(struct acomp_req *req,
                                         struct crypto_acomp *tfm)
 {
-       req->base.tfm = crypto_acomp_tfm(tfm);
+       crypto_request_set_tfm(&req->base, crypto_acomp_tfm(tfm));
 }
 
 static inline bool acomp_is_async(struct crypto_acomp *tfm)
@@ -298,6 +304,11 @@ static inline void *acomp_request_extra(struct acomp_req *req)
        return (void *)((char *)req + len);
 }
 
+static inline bool acomp_req_on_stack(struct acomp_req *req)
+{
+       return crypto_req_on_stack(&req->base);
+}
+
 /**
  * acomp_request_free() -- zeroize and free asynchronous (de)compression
  *                        request as well as the output buffer if allocated
@@ -307,7 +318,7 @@ static inline void *acomp_request_extra(struct acomp_req *req)
  */
 static inline void acomp_request_free(struct acomp_req *req)
 {
-       if (!req || (req->base.flags & CRYPTO_TFM_REQ_ON_STACK))
+       if (!req || acomp_req_on_stack(req))
                return;
        kfree_sensitive(req);
 }
@@ -328,15 +339,9 @@ static inline void acomp_request_set_callback(struct acomp_req *req,
                                              crypto_completion_t cmpl,
                                              void *data)
 {
-       u32 keep = CRYPTO_ACOMP_REQ_SRC_VIRT | CRYPTO_ACOMP_REQ_SRC_NONDMA |
-                  CRYPTO_ACOMP_REQ_DST_VIRT | CRYPTO_ACOMP_REQ_DST_NONDMA |
-                  CRYPTO_ACOMP_REQ_SRC_FOLIO | CRYPTO_ACOMP_REQ_DST_FOLIO |
-                  CRYPTO_TFM_REQ_ON_STACK;
-
-       req->base.complete = cmpl;
-       req->base.data = data;
-       req->base.flags &= keep;
-       req->base.flags |= flgs & ~keep;
+       flgs &= ~CRYPTO_ACOMP_REQ_PRIVATE;
+       flgs |= req->base.flags & CRYPTO_ACOMP_REQ_PRIVATE;
+       crypto_request_set_callback(&req->base, flgs, cmpl, data);
 }
 
 /**
index 960cdd1f3a573dfb051ca8b82f51bb28041415f7..5483ca5b46adb16fbeda66b042e3b6da429630ee 100644 (file)
@@ -229,4 +229,10 @@ static inline bool acomp_walk_more_src(const struct acomp_walk *walk, int cur)
 {
        return walk->slen != cur;
 }
+
+static inline u32 acomp_request_flags(struct acomp_req *req)
+{
+       return crypto_request_flags(&req->base) & ~CRYPTO_ACOMP_REQ_PRIVATE;
+}
+
 #endif