crypto: scompress - free partially allocated scratch buffers on failure
[linux-block.git] / crypto / scompress.c
index ae1d3cf209e4836b5cdbdf0e261caa9190e59bb4..2c07648305adc6823e7caaf28acca72416d4a89c 100644 (file)
@@ -125,8 +125,11 @@ static int crypto_scomp_alloc_all_scratches(void)
                if (!scomp_src_scratches)
                        return -ENOMEM;
                scomp_dst_scratches = crypto_scomp_alloc_scratches();
-               if (!scomp_dst_scratches)
+               if (!scomp_dst_scratches) {
+                       crypto_scomp_free_scratches(scomp_src_scratches);
+                       scomp_src_scratches = NULL;
                        return -ENOMEM;
+               }
        }
        return 0;
 }
@@ -211,9 +214,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
                                              scratch_dst, &req->dlen, *ctx);
        if (!ret) {
                if (!req->dst) {
-                       req->dst = crypto_scomp_sg_alloc(req->dlen,
-                                  req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
-                                  GFP_KERNEL : GFP_ATOMIC);
+                       req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC);
                        if (!req->dst)
                                goto out;
                }