Skip to contentSkip to conversation

zlib/gunzip: Use WATCHDOG_RESET macro

PATCH New Stefan Roese 3 participants 3 messages Sep 8, 2010 – Oct 12, 2010 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 zlib/gunzip: Use WATCHDOG_RESET macro

As usually done in U-Boot, the watchdog_reset code is called via a macro (WATCHDOG_RESET). In zlib.c this was done differently, by using a function pointer which is initialized with WATCHDOG_RESET upon watchdog usage or with NULL otherwise. This patch now uses the plain WATCHDOG_RESET macros to call the function resulting in slightly smaller U-Boot images and simpler code.

U-Boot code size reduction:

PowerPC board with watchdog support (lwmon5):
-> 80 bytes smaller image size

PowerPC board without watchdog support (sequoia):
-> 112 bytes smaller image size

Cc Detlev Zundel <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 lib/gunzip.c |    5 -----
 lib/zlib.c   |   10 ++++------
 2 files changed, 4 insertions(+), 11 deletions(-)
lib/gunzip.c +0 -5
index d2b7ad4..482a476 100644
@@ -96,11 +96,6 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
 
 	s.zalloc = zalloc;
 	s.zfree = zfree;
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	s.outcb = (cb_func)WATCHDOG_RESET;
-#else
-	s.outcb = Z_NULL;
-#endif	/* CONFIG_HW_WATCHDOG */
 
 	r = inflateInit2(&s, -MAX_WBITS);
 	if (r != Z_OK) {
lib/zlib.c +4 -6
index 26e5af1..2b31dba 100644
@@ -29,6 +29,7 @@
 #include <common.h>
 #include <compiler.h>
 #include <asm/unaligned.h>
+#include <watchdog.h>
 #include "u-boot/zlib.h"
 #undef	OFF				/* avoid conflicts */
 
@@ -1075,8 +1076,7 @@ z_streamp strm;
     state->hold = 0;
     state->bits = 0;
     state->lencode = state->distcode = state->next = state->codes;
-    if (strm->outcb != Z_NULL)
-	(*strm->outcb)(Z_NULL, 0);
+    WATCHDOG_RESET();
     Tracev((stderr, "inflate: reset\n"));
     return Z_OK;
 }
@@ -1776,8 +1776,7 @@ int flush;
             Tracev((stderr, "inflate:       codes ok\n"));
             state->mode = LEN;
         case LEN:
-            if (strm->outcb != Z_NULL) /* for watchdog (U-Boot) */
-                (*strm->outcb)(Z_NULL, 0);
+	    WATCHDOG_RESET();
             if (have >= 6 && left >= 258) {
                 RESTORE();
                 inflate_fast(strm, out);
@@ -1990,8 +1989,7 @@ z_streamp strm;
         return Z_STREAM_ERROR;
     state = (struct inflate_state FAR *)strm->state;
     if (state->window != Z_NULL) {
-	if (strm->outcb != Z_NULL)
-		(*strm->outcb)(Z_NULL, 0);
+	WATCHDOG_RESET();
 	ZFREE(strm, state->window);
     }
     ZFREE(strm, strm->state);
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/2 zlib/gunzip: Use WATCHDOG_RESET macro

Hi Stefan,

Quoted 12 lines

As usually done in U-Boot, the watchdog_reset code is called via a macro (WATCHDOG_RESET). In zlib.c this was done differently, by using a function pointer which is initialized with WATCHDOG_RESET upon watchdog usage or with NULL otherwise. This patch now uses the plain WATCHDOG_RESET macros to call the function resulting in slightly smaller U-Boot images and simpler code.

U-Boot code size reduction:

PowerPC board with watchdog support (lwmon5):
-> 80 bytes smaller image size

Quoted 6 lines

PowerPC board without watchdog support (sequoia):
-> 112 bytes smaller image size

Cc Detlev Zundel <[email protected]>
Cc Wolfgang Denk <[email protected]>

Thanks, now even I can understand the code ;)

Cheers
Detlev

Signature · 6 lines
A zen-buddhist walked into a pizza shop and
said, "Make me one with everything."
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#2 lore raw

PATCH 1/2 zlib/gunzip: Use WATCHDOG_RESET macro

In reply to Stefan Roese

Dear Stefan Roese,

Quoted 15 lines · In message <[email protected]> you wrote:

As usually done in U-Boot, the watchdog_reset code is called via a macro (WATCHDOG_RESET). In zlib.c this was done differently, by using a function pointer which is initialized with WATCHDOG_RESET upon watchdog usage or with NULL otherwise. This patch now uses the plain WATCHDOG_RESET macros to call the function resulting in slightly smaller U-Boot images and simpler code.

U-Boot code size reduction:

PowerPC board with watchdog support (lwmon5):
-> 80 bytes smaller image size

PowerPC board without watchdog support (sequoia):
-> 112 bytes smaller image size

Quoted 7 lines
Cc Detlev Zundel <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 lib/gunzip.c |    5 -----
 lib/zlib.c   |   10 ++++------
 2 files changed, 4 insertions(+), 11 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You could end up being oddly sad and full of a strange, diffuse  com-
passion  which would lead you to believe that it might be a good idea
to wipe out the whole human race and start again with amoebas.
                                 - Terry Pratchett, _Guards! Guards!_