Clean up of gzip decompressor
v2 cover Clean up of gzip decompressor
An issue ran into by hyperlaunch was the need to use the gzip decompressor multiple times. The current implementation fails when reused due to tainting of decompressor state from a previous usage. This series seeks to colocate the gzip unit files under a single directory similar to the other decompression algorithms. To enable the refactoring of the state tracking, the code is then cleaned up in line with Xen coding style.
Changes in v2:
- patch "xen/gzip: Colocate gunzip code files" was merged
- dropped ifdef chunks that are never enabled
- addressed formatting changes missed in v1
- replaced custom memory allocator with xalloc_bytes()
- renamed gzip_data to gzip_state
- moved gzip_state to being dynamically allocated
- changed crc table to the explicit size of uint32_t
- instead of moving huffman tracking into state, dropped altogether
Daniel P. Smith (6):
gzip: drop unused define checks
gzip: clean up comments and fix code alignment
gzip: remove custom memory allocator
gzip: refactor state tracking
gzip: move crc state into consilidated gzip state
gzip: drop huffman code table tracking
xen/common/gzip/gunzip.c | 87 ++-- xen/common/gzip/inflate.c | 974 ++++++++++++++++++-------------------- 2 files changed, 501 insertions(+), 560 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/6 gzip: drop unused define checks
Dropping the define checks for PKZIP_BUG_WORKAROUND and NOMEMCPY define as they never are set.
--- xen/common/gzip/inflate.c | 15 --------------- 1 file changed, 15 deletions(-)
xen/common/gzip/inflate.c +0 -15
@@ -661,7 +661,6 @@ static int __init inflate_codes(/* do the copy */ do { n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e); -#if !defined(NOMEMCPY) && !defined(DEBUG) if (w - d >= e) /* (this test assumes unsigned comparison) */ { memcpy(slide + w, slide + d, e);
@@ -669,7 +668,6 @@ static int __init inflate_codes( d += e; } else /* do it slow to avoid memcpy() overlap */ -#endif /* !NOMEMCPY */ do { slide[w++] = slide[d++];Tracevv ((stderr,"%c" , slide[w-1 ]));
@@ -845,11 +843,7 @@ static int noinline __init inflate_dynamic(void)DEBG ("<dyn" ); -#ifdef PKZIP_BUG_WORKAROUND - ll =malloc (sizeof (*ll) * (288 +32 ));/* literal/length and distance code lengths */ -#else ll =malloc (sizeof (*ll) * (286 +30 ));/* literal/length and distance code lengths */ -#endif if (ll ==NULL )return 1 ;
@@ -869,11 +863,7 @@ static int noinline __init inflate_dynamic(void)NEEDBITS (4 ) nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */ DUMPBITS(4) -#ifdef PKZIP_BUG_WORKAROUND -if (nl >288 || nd >32 ) -#elseif (nl >286 || nd >30 ) -#endif { ret =1 ;/* bad lengths */ goto out;
@@ -989,16 +979,11 @@ static int noinline __init inflate_dynamic(void)DEBG ("dyn5d " );if (i ==1 ) {error ("incomplete distance tree" ); -#ifdef PKZIP_BUG_WORKAROUND - i = 0; - } -#else huft_free (td); }huft_free (tl); ret = i;/* incomplete code set */ goto out; -#endif }DEBG ("dyn6 " );
Signature · 1 line
2.30.2
Re: [PATCH v2 1/6] gzip: drop unused define checks
Quoted 4 lines · Daniel P. Smith
Dropping the define checks for
PKZIP_BUG_WORKAROUNDand NOMEMCPY define as they never are set.Signed-off-by Daniel P. Smith <[email protected]>
It looks like ARCH_HAS_DECOMP_WDOG is another one that can go.
There's only a single instance, in inflate(), which I'm happy to fold on commit.
~Andrew
Re: [PATCH v2 1/6] gzip: drop unused define checks
In reply to Daniel P. SmithQuoted 2 lines · Daniel P. Smith
Dropping the define checks for
PKZIP_BUG_WORKAROUNDand NOMEMCPY define as they never are set.
You don't mention or otherwise touch DEBUG uses, yet ...
xen/common/gzip/inflate.c static int __init inflate_codes( · line 664
Quoted 7 lines
xen/common/gzip/inflate.c +0
-1@@ -661,7 +661,6 @@ static int __init inflate_codes(/* do the copy */ do { n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e); -#if !defined(NOMEMCPY) && !defined(DEBUG)
... you also don't replace this by "#ifndef DEBUG", but outright delete the line.
Jan
PATCH v2 2/6 gzip: clean up comments and fix code alignment
In reply to Daniel P. SmithThis commit cleans up the comments and fixes the code alignment using Xen coding style. This is done to make the code more legible before refactoring.
--- xen/common/gzip/gunzip.c | 10 +- xen/common/gzip/inflate.c | 790 +++++++++++++++++++------------------- 2 files changed, 405 insertions(+), 395 deletions(-)
xen/common/gzip/gunzip.c +9 -1
@@ -63,7 +63,6 @@ static __init int fill_inbuf(void)return 0 ; } -#include "inflate.c" static __init void flush_window (void )
@@ -137,3 +136,12 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len)return rc; } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/gzip/inflate.c +396 -394
1,050 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v2 3/6 gzip: remove custom memory allocator
In reply to Daniel P. SmithAll the other decompression routines use xmalloc_bytes(), thus there is no reason for gzip to be handling its own allocation of memory. In fact, there is a bug somewhere in the allocator as decompression started to break when adding additional allocations. Instead of troubleshooting the allocator, replace it with xmalloc_bytes().
--- xen/common/gzip/gunzip.c | 17 ++------------ xen/common/gzip/inflate.c | 47 --------------------------------------- 2 files changed, 2 insertions(+), 62 deletions(-)
xen/common/gzip/gunzip.c +2 -15
@@ -4,12 +4,7 @@#include <xen/lib.h> #include <xen/mm.h> -#define HEAPORDER 3 -static unsigned char *__initdata window; -#define memptr long -static memptr __initdata free_mem_ptr; -static memptr __initdata free_mem_end_ptr;#define WSIZE 0x80000000U
@@ -24,6 +19,8 @@ static unsigned int __initdata outcnt;#define OF (args) args +#define malloc (a) xmalloc_bytes(a) +#define free (a) xfree(a)#define memzero (s, n) memset((s), 0, (n))typedef unsigned char uch ;
@@ -108,14 +105,6 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len)return 1 ; window = (unsigned char *)output; - - free_mem_ptr = (unsigned long )alloc_xenheap_pages (HEAPORDER ,0 ); -if ( !free_mem_ptr ) -return -ENOMEM ; - - free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE <<HEAPORDER ); -init_allocator (); - inbuf = (unsigned char *)image; insize = image_len; inptr =0 ;
@@ -132,8 +121,6 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len) rc =0 ; } -free_xenheap_pages ((void *)free_mem_ptr,HEAPORDER ); -return rc; }
xen/common/gzip/inflate.c +0 -47
53 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v2 3/6] gzip: remove custom memory allocator
Quoted 11 lines · Daniel P. Smith
All the other decompression routines use
xmalloc_bytes(), thus there is no reason for gzip to be handling its own allocation of memory. In fact, there is a bug somewhere in the allocator as decompression started to break when adding additional allocations. Instead of troubleshooting the allocator, replace it withxmalloc_bytes().Signed-off-by Daniel P. Smith <[email protected]>--- xen/common/gzip/gunzip.c | 17 ++------------ xen/common/gzip/inflate.c | 47 --------------------------------------- 2 files changed, 2 insertions(+), 62 deletions(-)
Good riddance.
PATCH v2 4/6 gzip: refactor state tracking
In reply to Daniel P. SmithMove the core state into struct gzip_data to allow a per decompression instance.
--- xen/common/gzip/gunzip.c | 55 +++++++----- xen/common/gzip/inflate.c | 174 +++++++++++++++++++------------------- 2 files changed, 120 insertions(+), 109 deletions(-)
xen/common/gzip/gunzip.c +33 -22
@@ -4,18 +4,25 @@#include <xen/lib.h> #include <xen/mm.h> -static unsigned char *__initdata window; -#define WSIZE 0x80000000U -static unsigned char *__initdata inbuf; -static unsigned int __initdata insize; +struct gzip_state { +unsigned char *window; + +unsigned char *inbuf; +unsigned int insize; + +/* Index of next byte to be processed in inbuf: */ +unsigned int inptr; -/* Index of next byte to be processed in inbuf: */ -static unsigned int __initdata inptr; +/* Bytes in output buffer: */ +unsigned int outcnt; -/* Bytes in output buffer: */ -static unsigned int __initdata outcnt; +long bytes_out; + +unsigned long bb;/* bit buffer */ +unsigned bk;/* bits in bit buffer */ +};#define OF (args) args
@@ -27,7 +34,7 @@ typedef unsigned char uch;typedef unsigned short ush ;typedef unsigned long ulg ; -#define get_byte () (inptr < insize ? inbuf[inptr++] : fill_inbuf()) +#define get_byte () (s->inptr < s->insize ? s->inbuf[s->inptr++] : fill_inbuf())/* Diagnostic functions */ #ifdef DEBUG
@@ -46,8 +53,7 @@ typedef unsigned long ulg;# define Tracecv (c, x)#endif -static long __initdata bytes_out; -static void flush_window (void ); +static void flush_window (struct gzip_state *s);static __init void error (const char *x) {
@@ -62,7 +68,7 @@ static __init int fill_inbuf(void)#include "inflate.c" -static __init void flush_window (void ) +static __init void flush_window (struct gzip_state *s) {/* * The window is equal to the output buffer therefore only need to
@@ -72,16 +78,16 @@ static __init void flush_window(void)unsigned int n;unsigned char *in, ch; - in = window; -for ( n =0 ; n < outcnt; n++ ) + in = s->window; +for ( n =0 ; n < s->outcnt; n++ ) { ch = *in++; c = crc_32_tab[((int )c ^ ch) &0xff ] ^ (c >>8 ); } crc = c; - bytes_out += (unsigned long )outcnt; - outcnt =0 ; + s->bytes_out += (unsigned long )s->outcnt; + s->outcnt =0 ; }__init int gzip_check (char *image,unsigned long image_len)
@@ -99,20 +105,25 @@ __init int gzip_check(char *image, unsigned long image_len)__init int perform_gunzip (char *output,char *image,unsigned long image_len) { +struct gzip_state *s;int rc;if ( !gzip_check (image, image_len) )return 1 ; - window = (unsigned char *)output; - inbuf = (unsigned char *)image; - insize = image_len; - inptr =0 ; - bytes_out =0 ; + s = (struct gzip_state *)malloc (sizeof (struct gzip_state )); +if ( !s ) +return -ENOMEM ; + + s->window = (unsigned char *)output; + s->inbuf = (unsigned char *)image; + s->insize = image_len; + s->inptr =0 ; + s->bytes_out =0 ;makecrc (); -if (gunzip () <0 ) +if (gunzip (s) <0 ) { rc = -EINVAL ; }
xen/common/gzip/inflate.c +87 -87
468 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v2 4/6] gzip: refactor state tracking
Quoted 12 lines · Daniel P. Smith
xen/common/gzip/gunzip.c +0
-2@@ -4,18 +4,25 @@#include <xen/lib.h> #include <xen/mm.h> -static unsigned char *__initdata window; -#define WSIZE 0x80000000U
xen/common/gzip/gunzip.c line 16
Quoted 10 lines
xen/common/gzip/gunzip.c +8
-2-static unsigned char *__initdata inbuf; -static unsigned int __initdata insize; +struct gzip_state { +unsigned char *window; + +unsigned char *inbuf; +unsigned int insize; + +/* Index of next byte to be processed in inbuf: */ +unsigned int inptr;
perform_gunzip() passes in an unsigned long size, which means it's truncated in this state.
Please at least make these size_t. Life is too short to deal with the fallout of this going wrong.
xen/common/gzip/gunzip.c line 19
Quoted 5 lines
xen/common/gzip/gunzip.c +2
-2-/* Index of next byte to be processed in inbuf: */ -static unsigned int __initdata inptr; +/* Bytes in output buffer: */ +unsigned int outcnt;
See later, but I think the comment for outcnt is wrong.
xen/common/gzip/gunzip.c line 21
Quoted 4 lines
xen/common/gzip/gunzip.c +1
-2-/* Bytes in output buffer: */ -static unsigned int __initdata outcnt; +long bytes_out;
See later, but I don't think this can be signed. It's only used to cross-check the header-reported length, which is done as an unsigned long.
xen/common/gzip/gunzip.c line 24
Quoted 3 lines
xen/common/gzip/gunzip.c +3
-0+ +unsigned long bb;/* bit buffer */ +unsigned bk;/* bits in bit buffer */
As this is effectively new code, "unsigned int" please.
xen/common/gzip/gunzip.c typedef unsigned char uch; · line 37
Quoted 6 lines
xen/common/gzip/gunzip.c +1
-1@@ -27,7 +34,7 @@ typedef unsigned char uch;typedef unsigned short ush ;typedef unsigned long ulg ; -#define get_byte () (inptr < insize ? inbuf[inptr++] : fill_inbuf()) +#define get_byte () (s->inptr < s->insize ? s->inbuf[s->inptr++] : fill_inbuf())
This is a bit weird:
Quoted 6 lines
$ git grep -w get_byte common/gzip
common/gzip/gunzip.c:40:#define get_byte() (s->inptr < s->insize ?
s->inbuf[s->inptr++] : fill_inbuf())
common/gzip/inflate.c:224:#define NEXTBYTE(s) ({ int v = get_byte();
if (v < 0) goto underrun; (uch)v; })
common/gzip/inflate.c:1131: flags = (uch)get_byte();NEXTBYTE() gets an s parameter, but doesn't pass it to get_byte() and instead relies on state always having the name 's' in scope.
I'd suggest turning get_byte() into a proper static function. It will be more readable that throwing extra ()'s around s in the existing macro.
Except... fill_inbuf() is a fatal error anyway, so that can be folded together to simplify the result.
Quoted 7 lines
xen/common/gzip/gunzip.c +1
-2@@ -72,16 +78,16 @@ static __init void flush_window(void)unsigned int n;unsigned char *in, ch; - in = window; -for ( n =0 ; n < outcnt; n++ ) + in = s->window;
xen/common/gzip/gunzip.c static __init void flush_window(void) · line 89
Quoted 10 lines
xen/common/gzip/gunzip.c +2
-2+for ( n =0 ; n < s->outcnt; n++ ) { ch = *in++; c = crc_32_tab[((int )c ^ ch) &0xff ] ^ (c >>8 ); } crc = c; - bytes_out += (unsigned long )outcnt; - outcnt =0 ; + s->bytes_out += (unsigned long )s->outcnt;
I can't figure out why this was written this way, even originally.
AFAICT, outcnt doesn't even match it's comment.
/* Bytes in output buffer: */
It looks like it's the number of bytes in window. This also matches the "wp" define which I guess is "window position".
Anyway, irrespective of naming, the cast is useless so lets drop it while modifying the line.
xen/common/gzip/inflate.c static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #"; · line 122
Quoted 10 lines
xen/common/gzip/inflate.c +1
-1@@ -119,7 +119,7 @@ static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #";#endif /* !__XEN__ */ -#define slide window +#define slide s->window
Given only 8 uses, I'd expand this in place and drop the macro.
But, there's an entire comment block discussing "slide" which I think is wrong for Xen's implementation. That wants to go too, I think.
Quoted 9 lines
xen/common/gzip/inflate.c +0
-2/* * Huffman code lookup table entry--this entry is four bytes for machines @@ -143,12 +143,12 @@ struct huft { static int huft_build OF((unsigned *, unsigned, unsigned, const ush *, const ush *, struct huft **, int *)); static int huft_free OF((struct huft *)); -static int inflate_codes OF((struct huft *, struct huft *, int, int)); -static int inflate_stored OF((void));
xen/common/gzip/inflate.c struct huft { · line 151
Quoted 10 lines
xen/common/gzip/inflate.c +6
-4-static int inflate_fixed OF((void)); -static int inflate_dynamic OF((void)); -static int inflate_block OF((int *)); -static int inflate OF((void)); +static int inflate_codes OF((struct gzip_state *, struct huft *, struct huft *, int, int)); +static int inflate_stored OF((struct gzip_state *)); +static int inflate_fixed OF((struct gzip_state *)); +static int inflate_dynamic OF((struct gzip_state *)); +static int inflate_block OF((struct gzip_state *, int *)); +static int inflate OF((struct gzip_state *));
These are the only users of OF, and it turns out it's a no-op macro. This code would be far-less WTF-worthy if it was expanded as part of patch 1.
xen/common/gzip/inflate.c static int inflate OF((void)); · line 166
Quoted 11 lines
xen/common/gzip/inflate.c +2
-2/* * The inflate algorithm uses a sliding 32 K byte window on the uncompressed @@ -162,8 +162,8 @@ static int inflate OF((void));* must be in unzip.h, included above. */ /* unsigned wp; current position in slide */ -#define wp outcnt -#define flush_output (w) (wp=(w),flush_window()) +#define wp s->outcnt +#define flush_output (s, w) (wp=(w),flush_window(s))
The combination of these two isn't safe, I don't think, especially as one caller passes wp into flush_output().
There are very few users of wp, so expand it in line, and turn flush_output() into a static function. In particular, it will make ...
xen/common/gzip/inflate.c static int __init inflate_codes( · line 562
Quoted 9 lines
xen/common/gzip/inflate.c +2
-2@@ -560,8 +557,8 @@ static int __init inflate_codes(/* make local copies of globals */ - b = bb;/* initialize bit buffer */ - k = bk; + b = s->bb;/* initialize bit buffer */ + k = s->bk; w = wp;/* initialize window position */
... this look less weird. I'd suggest dropping the remark about "globals".
Quoted 7 lines
xen/common/gzip/inflate.c +0
-3@@ -1157,18 +1157,18 @@ static int __init gunzip(void)error ("Input has invalid flags" );return -1 ; } -NEXTBYTE ();/* Get timestamp */ -NEXTBYTE (); -NEXTBYTE ();
xen/common/gzip/inflate.c static int __init gunzip(void) · line 1166
Quoted 10 lines
xen/common/gzip/inflate.c +6
-3-NEXTBYTE (); +NEXTBYTE (s);/* Get timestamp */ +NEXTBYTE (s); +NEXTBYTE (s); +NEXTBYTE (s); - (void )NEXTBYTE ();/* Ignore extra flags for the moment */ - (void )NEXTBYTE ();/* Ignore OS type for the moment */ + (void )NEXTBYTE (s);/* Ignore extra flags for the moment */ + (void )NEXTBYTE (s);/* Ignore OS type for the moment */
I'd drop these (void) casts. They're not different to the timestamp above.
Quoted 5 lines
xen/common/gzip/inflate.c +0
-1@@ -1224,13 +1224,13 @@ static int __init gunzip(void)error ("crc error" );return -1 ; } -if (orig_len != bytes_out) {
xen/common/gzip/inflate.c static int __init gunzip(void) · line 1235
Quoted 10 lines
xen/common/gzip/inflate.c +2
-1+if (orig_len != s->bytes_out) {error ("length error" );return -1 ; }return 0 ; - underrun:/* NEXTBYTE() goto's here if needed */ + underrun:/* NEXTBYTE(s) goto's here if needed */ error ("out of input data" );return -1 ;
Just for completeness, this is a dead path because fill_inbuf() is implemented as panic().
Fixing this wants putting on a todo list somewhere.
~Andrew
PATCH v2 5/6 gzip: move crc state into consilidated gzip state
In reply to Daniel P. Smith--- xen/common/gzip/gunzip.c | 11 +++++++---- xen/common/gzip/inflate.c | 12 +++++------- 2 files changed, 12 insertions(+), 11 deletions(-)
xen/common/gzip/gunzip.c +7 -4
@@ -22,6 +22,9 @@ struct gzip_state {unsigned long bb;/* bit buffer */ unsigned bk;/* bits in bit buffer */ + +uint32_t crc_32_tab[256 ]; +uint32_t crc; };#define OF (args) args
@@ -74,7 +77,7 @@ static __init void flush_window(struct gzip_state *s)* The window is equal to the output buffer therefore only need to * compute the crc. */ -unsigned long c = crc; +unsigned long c = s->crc;unsigned int n;unsigned char *in, ch;
@@ -82,9 +85,9 @@ static __init void flush_window(struct gzip_state *s)for ( n =0 ; n < s->outcnt; n++ ) { ch = *in++; - c = crc_32_tab[((int )c ^ ch) &0xff ] ^ (c >>8 ); + c = s->crc_32_tab[((int )c ^ ch) &0xff ] ^ (c >>8 ); } - crc = c; + s->crc = c; s->bytes_out += (unsigned long )s->outcnt; s->outcnt =0 ;
@@ -121,7 +124,7 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len) s->inptr =0 ; s->bytes_out =0 ; -makecrc (); +makecrc (s);if (gunzip (s) <0 ) {
xen/common/gzip/inflate.c +5 -7
@@ -1063,16 +1063,14 @@ static int __init inflate(struct gzip_state *s)* **********************************************************************/ -static ulg __initdata crc_32_tab[256 ]; -static ulg __initdata crc;/* initialized in makecrc() so it'll reside in bss */ -#define CRC_VALUE (crc ^ 0xffffffffUL) +#define CRC_VALUE (s->crc ^ 0xffffffffUL)/* * Code to compute the CRC-32 table. Borrowed from * gzip-1.0.3/makecrc.c. */ -static void __init makecrc (void ) +static void __init makecrc (struct gzip_state *s) {/* Not copyrighted 1990 Mark Adler */
@@ -1089,7 +1087,7 @@ static void __init makecrc(void)for (i =0 ; i <sizeof (p)/sizeof (int ); i++) e |=1L << (31 - p[i]); - crc_32_tab[0 ] =0 ; + s->crc_32_tab[0 ] =0 ;for (i =1 ; i <256 ; i++) {
@@ -1100,11 +1098,11 @@ static void __init makecrc(void)if (k &1 ) c ^= e; } - crc_32_tab[i] = c; + s->crc_32_tab[i] = c; }/* this is initialized here so this code could reside in ROM */ - crc = (ulg )0xffffffffUL ;/* shift register contents */ + s->crc = (ulg )0xffffffffUL ;/* shift register contents */ }/* gzip flag byte */
Signature · 1 line
2.30.2
Re: [PATCH v2 5/6] gzip: move crc state into consilidated gzip state
Quoted 1 line · Daniel P. Smith
Signed-off-by Daniel P. Smith <[email protected]>
The change in type is fine, but does need discussing. Furthermore, ...
xen/common/gzip/gunzip.c static __init void flush_window(struct gzip_state *s) · line 80
Quoted 10 lines
xen/common/gzip/gunzip.c +1
-1@@ -74,7 +77,7 @@ static __init void flush_window(struct gzip_state *s)* The window is equal to the output buffer therefore only need to * compute the crc. */ -unsigned long c = crc; +unsigned long c = s->crc;
... this wants to be unsigned int I think.
xen/common/gzip/inflate.c static int __init inflate(struct gzip_state *s) · line 1066
Quoted 12 lines
xen/common/gzip/inflate.c +1
-3@@ -1063,16 +1063,14 @@ static int __init inflate(struct gzip_state *s)* **********************************************************************/ -static ulg __initdata crc_32_tab[256 ]; -static ulg __initdata crc;/* initialized in makecrc() so it'll reside in bss */ -#define CRC_VALUE (crc ^ 0xffffffffUL) +#define CRC_VALUE (s->crc ^ 0xffffffffUL)
$ git grep CRC_VALUE
common/gzip/inflate.c:1052:#define CRC_VALUE (s->crc ^ 0xffffffffUL)
common/gzip/inflate.c:1207: if (orig_crc != CRC_VALUE) {I'd expand this in it's single user, but like ...
Quoted 21 lines
xen/common/gzip/inflate.c +2
-2/* * Code to compute the CRC-32 table. Borrowed from * gzip-1.0.3/makecrc.c. */ -static void __init makecrc (void ) +static void __init makecrc (struct gzip_state *s) {/* Not copyrighted 1990 Mark Adler */ @@ -1089,7 +1087,7 @@ static void __init makecrc(void)for (i =0 ; i <sizeof (p)/sizeof (int ); i++) e |=1L << (31 - p[i]); - crc_32_tab[0 ] =0 ; + s->crc_32_tab[0 ] =0 ;for (i =1 ; i <256 ; i++) {
xen/common/gzip/inflate.c static void __init makecrc(void) · line 1105
Quoted 10 lines
xen/common/gzip/inflate.c +2
-2@@ -1100,11 +1098,11 @@ static void __init makecrc(void)if (k &1 ) c ^= e; } - crc_32_tab[i] = c; + s->crc_32_tab[i] = c; }/* this is initialized here so this code could reside in ROM */ - crc = (ulg )0xffffffffUL ;/* shift register contents */ + s->crc = (ulg )0xffffffffUL ;/* shift register contents */
... this, the constant should become -1u or ~0u because of the type change.
I'm not sure what to make of the ROM comment, but I suspect it means the XOR can be dropped with a bit of care too.
~Andrew
PATCH v2 6/6 gzip: drop huffman code table tracking
In reply to Daniel P. SmithThe "tracking" bits does not appear to be used, so dropping from the code.
--- xen/common/gzip/inflate.c | 6 ------ 1 file changed, 6 deletions(-)
xen/common/gzip/inflate.c +0 -6
@@ -264,8 +264,6 @@ static const int dbits = 6; /* bits in base distance lookup table */#define BMAX 16/* maximum bit length of any code (16 for explode) */ #define N_MAX 288/* maximum number of codes in any set */ -static unsigned __initdata hufts;/* track memory usage */ -/* * Given a list of code lengths and a maximum table size, make a set of * tables to decode that set of codes. Return zero on success, one if
@@ -445,7 +443,6 @@ static int __init huft_build( goto out; }DEBG1 ("4 " ); - hufts += z +1 ;/* track memory usage */ *t = q +1 ;/* link to list for huft_free() */ *(t = &(q->v.t)) = (struct huft *)NULL ; u[h] = ++q;/* table starts after link */
@@ -1028,15 +1025,12 @@ static int __init inflate(struct gzip_state *s)/* decompress until the last block */ h =0 ;do { - hufts =0 ;#ifdef ARCH_HAS_DECOMP_WDOG arch_decomp_wdog ();#endif r =inflate_block (s, &e);if (r)return r; -if (hufts > h) - h = hufts; }while (!e);/* Undo too much lookahead. The next read will be byte aligned so we
Signature · 1 line
2.30.2
Re: [PATCH v2 6/6] gzip: drop huffman code table tracking
Quoted 32 lines · Daniel P. Smith
The "tracking" bits does not appear to be used, so dropping from the code.
Signed-off-by Daniel P. Smith <[email protected]>--- xen/common/gzip/inflate.c | 6 ------ 1 file changed, 6 deletions(-)xen/common/gzip/inflate.c +0
-3@@ -264,8 +264,6 @@ static const int dbits = 6; /* bits in base distance lookup table */#define BMAX 16/* maximum bit length of any code (16 for explode) */ #define N_MAX 288/* maximum number of codes in any set */ -static unsigned __initdata hufts;/* track memory usage */ -/* * Given a list of code lengths and a maximum table size, make a set of * tables to decode that set of codes. Return zero on success, one if @@ -445,7 +443,6 @@ static int __init huft_build( goto out; }DEBG1 ("4 " ); - hufts += z +1 ;/* track memory usage */ *t = q +1 ;/* link to list for huft_free() */ *(t = &(q->v.t)) = (struct huft *)NULL ; u[h] = ++q;/* table starts after link */ @@ -1028,15 +1025,12 @@ static int __init inflate(struct gzip_state *s)/* decompress until the last block */ h =0 ; do {
xen/common/gzip/inflate.c static int __init inflate(struct gzip_state *s) · line 1034
Quoted 10 lines
xen/common/gzip/inflate.c +0
-3- hufts =0 ;#ifdef ARCH_HAS_DECOMP_WDOG arch_decomp_wdog ();#endif r =inflate_block (s, &e);if (r)return r; -if (hufts > h) - h = hufts; }while (!e);
With 'hufts' removed, the local variable 'h' is now dead too. It gets read inside an #ifdef DEBUG, but as it's rendering a unqualified number to stderr, it can also be deleted.
Specifically, I recommend this additional delta:
xen/common/gzip/inflate.c +0 -0
@@ -1015,7 +1015,6 @@ static int __init inflate(struct gzip_state *s)
{
int e; /* last block flag */
int r; /* result code */
- unsigned h; /* maximum struct huft's malloc'ed */
/* initialize window, bit buffer */
wp = 0;
@@ -1023,7 +1022,6 @@ static int __init inflate(struct gzip_state *s) s->bb = 0;
/* decompress until the last block */
- h = 0;
do {
#ifdef ARCH_HAS_DECOMP_WDOG
arch_decomp_wdog();
@@ -1045,9 +1043,6 @@ static int __init inflate(struct gzip_state *s) flush_output(s, wp);
/* return success */
-#ifdef DEBUG
- fprintf(stderr, "<%u> ", h);
-#endif /* DEBUG */
return 0;
}
which I'm happy to fold on commit.
~Andrew
Quoted 6 lines · Daniel P. Smith
An issue ran into by hyperlaunch was the need to use the gzip decompressor multiple times. The current implementation fails when reused due to tainting of decompressor state from a previous usage. This series seeks to colocate the gzip unit files under a single directory similar to the other decompression algorithms. To enable the refactoring of the state tracking, the code is then cleaned up in line with Xen coding style.
I don't mind the content and style adjustments, but what I'm missing here and in the patch descriptions is weighing of doing so versus ease of importing changes to the original source.
Jan