From patchwork Mon Jan 5 20:12:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [MTD-UTILS,compr_lzo.c] Fix calls to liblzo library Date: Mon, 05 Jan 2009 10:12:30 -0000 From: Carsten Schlote X-Patchwork-Id: 16799 Message-Id: <1231186350.6612.11.camel@kplaws107lx> To: Linux MTD Dev This patch fixes the calls to liblzo. Some things shouldn't ever worked before. I noticed the problem on 64bit Linux - suddently mkfs.jffs2 starts segfaulting. The -t option didn't work as well. Now LZO compression and -t option of mkfs.jffs2 is functional again. http://www.vahanus.net/cgi-bin/gitweb.cgi?p=mtd-utils.git;a=commit;h=5cec421106993009ad43e6188ce44906138c2d38 diff --git a/compr_lzo.c b/compr_lzo.c index a0bb362..f4ae697 100644 --- a/compr_lzo.c +++ b/compr_lzo.c @@ -48,17 +48,19 @@ static void *lzo_compress_buf; static int jffs2_lzo_cmpr(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen, void *model) { - uint32_t compress_size; + lzo_uint compress_size; int ret; ret = lzo1x_999_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem); - if (ret != LZO_E_OK) + if (ret != LZO_E_OK) { + printf(__FILE__ ":Got compress error: ret=%d, cl=%ld, destlen=%ld\n",ret,compress_size,(long int)(*dstlen)); return -1; + } if (compress_size > *dstlen) return -1; - + memcpy(cpage_out, lzo_compress_buf, compress_size); *dstlen = compress_size; @@ -69,12 +71,15 @@ static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out uint32_t srclen, uint32_t destlen, void *model) { int ret; - uint32_t dl; + lzo_uint dl; + dl = destlen; ret = lzo1x_decompress_safe(data_in,srclen,cpage_out,&dl,NULL); - if (ret != LZO_E_OK || dl != destlen) + if ((ret != LZO_E_OK) || (dl != destlen)) { + printf(__FILE__ ":Got decompress error: ret=%d, dl=%ld, destlen=%ld\n",ret,dl,(long int)destlen); return -1; + } return 0; } @@ -92,12 +97,22 @@ int jffs2_lzo_init(void) { int ret; + lzo_init(); + lzo_mem = malloc(LZO1X_999_MEM_COMPRESS); if (!lzo_mem) return -1; /* Worse case LZO compression size from their FAQ */ - lzo_compress_buf = malloc(page_size + (page_size / 16) + 64 + 3); + /* Dangerous: Seems to be wrong for 64bit intel platforms. At least it results + into s SEGV. + + lzo_compress_buf = malloc(page_size + (page_size / 16) + 64 + 3); + + The line below fixes the SEGV. No further work has be done to determine + the smallest possible size for a worstcase scenario (uncompressable data) + */ + lzo_compress_buf = malloc(2*page_size); if (!lzo_compress_buf) { free(lzo_mem); return -1;