Commit 3ce858cb authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Herbert Xu

crypto: compress - Return produced bytes in crypto_{,de}compress_{update,final}

If crypto_{,de}compress_{update,final}() succeed, return the actual number of
bytes produced instead of zero, so their users don't have to calculate that
theirselves.
Signed-off-by: default avatarGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent e9736c16
...@@ -1002,24 +1002,25 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1002,24 +1002,25 @@ static int test_pcomp(struct crypto_pcomp *tfm,
const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
unsigned int i; unsigned int i;
char result[COMP_BUF_SIZE]; char result[COMP_BUF_SIZE];
int error; int res;
for (i = 0; i < ctcount; i++) { for (i = 0; i < ctcount; i++) {
struct comp_request req; struct comp_request req;
unsigned int produced = 0;
error = crypto_compress_setup(tfm, ctemplate[i].params, res = crypto_compress_setup(tfm, ctemplate[i].params,
ctemplate[i].paramsize); ctemplate[i].paramsize);
if (error) { if (res) {
pr_err("alg: pcomp: compression setup failed on test " pr_err("alg: pcomp: compression setup failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
error = crypto_compress_init(tfm); res = crypto_compress_init(tfm);
if (error) { if (res) {
pr_err("alg: pcomp: compression init failed on test " pr_err("alg: pcomp: compression init failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
memset(result, 0, sizeof(result)); memset(result, 0, sizeof(result));
...@@ -1029,32 +1030,37 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1029,32 +1030,37 @@ static int test_pcomp(struct crypto_pcomp *tfm,
req.next_out = result; req.next_out = result;
req.avail_out = ctemplate[i].outlen / 2; req.avail_out = ctemplate[i].outlen / 2;
error = crypto_compress_update(tfm, &req); res = crypto_compress_update(tfm, &req);
if (error && (error != -EAGAIN || req.avail_in)) { if (res < 0 && (res != -EAGAIN || req.avail_in)) {
pr_err("alg: pcomp: compression update failed on test " pr_err("alg: pcomp: compression update failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
if (res > 0)
produced += res;
/* Add remaining input data */ /* Add remaining input data */
req.avail_in += (ctemplate[i].inlen + 1) / 2; req.avail_in += (ctemplate[i].inlen + 1) / 2;
error = crypto_compress_update(tfm, &req); res = crypto_compress_update(tfm, &req);
if (error && (error != -EAGAIN || req.avail_in)) { if (res < 0 && (res != -EAGAIN || req.avail_in)) {
pr_err("alg: pcomp: compression update failed on test " pr_err("alg: pcomp: compression update failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
if (res > 0)
produced += res;
/* Provide remaining output space */ /* Provide remaining output space */
req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
error = crypto_compress_final(tfm, &req); res = crypto_compress_final(tfm, &req);
if (error) { if (res < 0) {
pr_err("alg: pcomp: compression final failed on test " pr_err("alg: pcomp: compression final failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
produced += res;
if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
pr_err("alg: comp: Compression test %d failed for %s: " pr_err("alg: comp: Compression test %d failed for %s: "
...@@ -1064,6 +1070,13 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1064,6 +1070,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
if (produced != ctemplate[i].outlen) {
pr_err("alg: comp: Compression test %d failed for %s: "
"returned len = %u (expected %d)\n", i + 1,
algo, produced, ctemplate[i].outlen);
return -EINVAL;
}
if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
pr_err("alg: pcomp: Compression test %d failed for " pr_err("alg: pcomp: Compression test %d failed for "
"%s\n", i + 1, algo); "%s\n", i + 1, algo);
...@@ -1074,21 +1087,21 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1074,21 +1087,21 @@ static int test_pcomp(struct crypto_pcomp *tfm,
for (i = 0; i < dtcount; i++) { for (i = 0; i < dtcount; i++) {
struct comp_request req; struct comp_request req;
unsigned int produced = 0;
error = crypto_decompress_setup(tfm, dtemplate[i].params, res = crypto_decompress_setup(tfm, dtemplate[i].params,
dtemplate[i].paramsize); dtemplate[i].paramsize);
if (error) { if (res) {
pr_err("alg: pcomp: decompression setup failed on " pr_err("alg: pcomp: decompression setup failed on "
"test %d for %s: error=%d\n", i + 1, algo, "test %d for %s: error=%d\n", i + 1, algo, res);
error); return res;
return error;
} }
error = crypto_decompress_init(tfm); res = crypto_decompress_init(tfm);
if (error) { if (res) {
pr_err("alg: pcomp: decompression init failed on test " pr_err("alg: pcomp: decompression init failed on test "
"%d for %s: error=%d\n", i + 1, algo, error); "%d for %s: error=%d\n", i + 1, algo, res);
return error; return res;
} }
memset(result, 0, sizeof(result)); memset(result, 0, sizeof(result));
...@@ -1098,35 +1111,38 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1098,35 +1111,38 @@ static int test_pcomp(struct crypto_pcomp *tfm,
req.next_out = result; req.next_out = result;
req.avail_out = dtemplate[i].outlen / 2; req.avail_out = dtemplate[i].outlen / 2;
error = crypto_decompress_update(tfm, &req); res = crypto_decompress_update(tfm, &req);
if (error && (error != -EAGAIN || req.avail_in)) { if (res < 0 && (res != -EAGAIN || req.avail_in)) {
pr_err("alg: pcomp: decompression update failed on " pr_err("alg: pcomp: decompression update failed on "
"test %d for %s: error=%d\n", i + 1, algo, "test %d for %s: error=%d\n", i + 1, algo, res);
error); return res;
return error;
} }
if (res > 0)
produced += res;
/* Add remaining input data */ /* Add remaining input data */
req.avail_in += (dtemplate[i].inlen + 1) / 2; req.avail_in += (dtemplate[i].inlen + 1) / 2;
error = crypto_decompress_update(tfm, &req); res = crypto_decompress_update(tfm, &req);
if (error && (error != -EAGAIN || req.avail_in)) { if (res < 0 && (res != -EAGAIN || req.avail_in)) {
pr_err("alg: pcomp: decompression update failed on " pr_err("alg: pcomp: decompression update failed on "
"test %d for %s: error=%d\n", i + 1, algo, "test %d for %s: error=%d\n", i + 1, algo, res);
error); return res;
return error;
} }
if (res > 0)
produced += res;
/* Provide remaining output space */ /* Provide remaining output space */
req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
error = crypto_decompress_final(tfm, &req); res = crypto_decompress_final(tfm, &req);
if (error && (error != -EAGAIN || req.avail_in)) { if (res < 0 && (res != -EAGAIN || req.avail_in)) {
pr_err("alg: pcomp: decompression final failed on " pr_err("alg: pcomp: decompression final failed on "
"test %d for %s: error=%d\n", i + 1, algo, "test %d for %s: error=%d\n", i + 1, algo, res);
error); return res;
return error;
} }
if (res > 0)
produced += res;
if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
pr_err("alg: comp: Decompression test %d failed for " pr_err("alg: comp: Decompression test %d failed for "
...@@ -1136,6 +1152,13 @@ static int test_pcomp(struct crypto_pcomp *tfm, ...@@ -1136,6 +1152,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
if (produced != dtemplate[i].outlen) {
pr_err("alg: comp: Decompression test %d failed for "
"%s: returned len = %u (expected %d)\n", i + 1,
algo, produced, dtemplate[i].outlen);
return -EINVAL;
}
if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
pr_err("alg: pcomp: Decompression test %d failed for " pr_err("alg: pcomp: Decompression test %d failed for "
"%s\n", i + 1, algo); "%s\n", i + 1, algo);
......
...@@ -165,15 +165,15 @@ static int zlib_compress_update(struct crypto_pcomp *tfm, ...@@ -165,15 +165,15 @@ static int zlib_compress_update(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out, stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, req->avail_in - stream->avail_in, ret);
req->avail_out - stream->avail_out);
req->next_in = stream->next_in; req->next_in = stream->next_in;
req->avail_in = stream->avail_in; req->avail_in = stream->avail_in;
req->next_out = stream->next_out; req->next_out = stream->next_out;
req->avail_out = stream->avail_out; req->avail_out = stream->avail_out;
return 0; return ret;
} }
static int zlib_compress_final(struct crypto_pcomp *tfm, static int zlib_compress_final(struct crypto_pcomp *tfm,
...@@ -195,15 +195,15 @@ static int zlib_compress_final(struct crypto_pcomp *tfm, ...@@ -195,15 +195,15 @@ static int zlib_compress_final(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out, stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, req->avail_in - stream->avail_in, ret);
req->avail_out - stream->avail_out);
req->next_in = stream->next_in; req->next_in = stream->next_in;
req->avail_in = stream->avail_in; req->avail_in = stream->avail_in;
req->next_out = stream->next_out; req->next_out = stream->next_out;
req->avail_out = stream->avail_out; req->avail_out = stream->avail_out;
return 0; return ret;
} }
...@@ -280,15 +280,15 @@ static int zlib_decompress_update(struct crypto_pcomp *tfm, ...@@ -280,15 +280,15 @@ static int zlib_decompress_update(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out, stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, req->avail_in - stream->avail_in, ret);
req->avail_out - stream->avail_out);
req->next_in = stream->next_in; req->next_in = stream->next_in;
req->avail_in = stream->avail_in; req->avail_in = stream->avail_in;
req->next_out = stream->next_out; req->next_out = stream->next_out;
req->avail_out = stream->avail_out; req->avail_out = stream->avail_out;
return 0; return ret;
} }
static int zlib_decompress_final(struct crypto_pcomp *tfm, static int zlib_decompress_final(struct crypto_pcomp *tfm,
...@@ -328,15 +328,15 @@ static int zlib_decompress_final(struct crypto_pcomp *tfm, ...@@ -328,15 +328,15 @@ static int zlib_decompress_final(struct crypto_pcomp *tfm,
return -EINVAL; return -EINVAL;
} }
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out, stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, req->avail_in - stream->avail_in, ret);
req->avail_out - stream->avail_out);
req->next_in = stream->next_in; req->next_in = stream->next_in;
req->avail_in = stream->avail_in; req->avail_in = stream->avail_in;
req->next_out = stream->next_out; req->next_out = stream->next_out;
req->avail_out = stream->avail_out; req->avail_out = stream->avail_out;
return 0; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment