{
struct ll_compr_hdr *llch;
unsigned int len = *out_len - sizeof(*llch);
+ int effective_uncompr_size;
+ int effective_compr_size;
int rc;
+ /* the uncompressed data is shorter than the minimum effective
+ * compressed size, so don't bother compressing
+ */
+ if (in_len <= COMP_GAP) {
+ *out_len = in_len;
+ return 0;
+ }
+
rc = crypto_comp_compress(cc, in, in_len,
out + sizeof(*llch),
&len);
return 0;
}
- if (len + sizeof(*llch) + COMP_GAP > in_len) {
+ /* round the sizes up to the nearest block before comparing */
+ effective_compr_size = round_up(len + sizeof(*llch), COMP_GAP);
+ effective_uncompr_size = round_up(in_len, COMP_GAP);
+
+ if (effective_compr_size >= effective_uncompr_size) {
CDEBUG(D_SEC,
- "Compressed %u + overhead %lu > plain %u, leaving uncompressed\n",
- len, sizeof(*llch) + COMP_GAP, in_len);
+ "Compressed %u + overhead %u > plain %u + overhead %u, leaving uncompressed\n",
+ len, effective_compr_size - len, in_len,
+ effective_uncompr_size - in_len);
*out_len = in_len;
return 0;
}