@@ -71,9 +71,13 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
acomp->compress = alg->compress;
acomp->decompress = alg->decompress;
+
acomp->dst_free = alg->dst_free;
acomp->reqsize = alg->reqsize;
+ acomp->pre_alloc = alg->pre_alloc;
+ acomp->post_free = alg->post_free;
+
if (alg->exit)
acomp->base.exit = crypto_acomp_exit_tfm;
@@ -129,6 +133,12 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
struct acomp_req *req;
req = __acomp_request_alloc(acomp);
+
+ if (req && (acomp->pre_alloc && acomp->pre_alloc(req))) {
+ __acomp_request_free(req);
+ return NULL;
+ }
+
if (req && (tfm->__crt_alg->cra_type != &crypto_acomp_type))
return crypto_acomp_scomp_alloc_ctx(req);
@@ -144,6 +154,9 @@ void acomp_request_free(struct acomp_req *req)
if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
crypto_acomp_scomp_free_ctx(req);
+ if (acomp->post_free)
+ acomp->post_free(req);
+
if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) {
acomp->dst_free(req->dst);
req->dst = NULL;
@@ -51,6 +51,8 @@ struct acomp_req {
struct crypto_acomp {
int (*compress)(struct acomp_req *req);
int (*decompress)(struct acomp_req *req);
+ int (*pre_alloc)(struct acomp_req *req);
+ void (*post_free)(struct acomp_req *req);
void (*dst_free)(struct scatterlist *dst);
unsigned int reqsize;
struct crypto_tfm base;
@@ -29,6 +29,10 @@
* @exit: Deinitialize the cryptographic transformation object. This is a
* counterpart to @init, used to remove various changes set in
* @init.
+ * @pre_alloc: Function that performs any pre-allocation and setup that an
+ * algorithm may require on a per req basis.
+ * @post_free: Function that performs any post freeing that an algorithm
+ * may require on a per req basis.
*
* @reqsize: Context size for (de)compression requests
* @base: Common crypto API algorithm data structure
@@ -40,6 +44,8 @@ struct acomp_alg {
void (*dst_free)(struct scatterlist *dst);
int (*init)(struct crypto_acomp *tfm);
void (*exit)(struct crypto_acomp *tfm);
+ int (*pre_alloc)(struct acomp_req *req);
+ void (*post_free)(struct acomp_req *req);
unsigned int reqsize;
Add callbacks to acomp crypto algorithms that facilitate the allocation and subsequent freeing of resources required by an acomp_req before and after a series of compress and/or decompress operations. Signed-off-by: Andre Glover <andre.glover@linux.intel.com> --- crypto/acompress.c | 13 +++++++++++++ include/crypto/acompress.h | 2 ++ include/crypto/internal/acompress.h | 6 ++++++ 3 files changed, 21 insertions(+)