From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@osdl.org>, linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Subject: [PATCH 9/20] inflate: (arch) refactor inflate malloc code
Date: Mon, 31 Oct 2005 14:54:48 -0600 [thread overview]
Message-ID: <10.196662837@selenic.com> (raw)
In-Reply-To: <9.196662837@selenic.com>
inflate: refactor inflate malloc code
Inflate requires some dynamic memory allocation very early in the boot
process and this is provided with a set of four functions:
malloc/free/gzip_mark/gzip_release.
The old inflate code used a mark/release strategy rather than
implement free. This new version instead keeps a count on the number
of outstanding allocations and when it hits zero, it resets the malloc
arena.
This allows removing all the mark and release implementations and
unifying all the malloc/free implementations.
This also fixes bogus usage of malloc/free rather than kmalloc/kfree
in initramfs.c.
Signed-off-by: Matt Mackall <mpm@selenic.com>
Index: 2.6.14/arch/alpha/boot/misc.c
===================================================================
--- 2.6.14.orig/arch/alpha/boot/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/alpha/boot/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
@@ -49,8 +47,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
static char *input_data;
static int input_data_size;
@@ -59,12 +55,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
extern int end;
static ulg free_mem_ptr;
static ulg free_mem_ptr_end;
@@ -73,37 +63,6 @@ static ulg free_mem_ptr_end;
#include "../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/arm/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/arm/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
@@ -67,8 +65,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char input_data[];
extern char input_data_end[];
@@ -77,12 +73,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void putstr(const char *);
extern int end;
@@ -93,47 +83,8 @@ static ulg free_mem_ptr_end;
#include "../../../../lib/inflate.c"
-#ifndef STANDALONE_DEBUG
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- arch_decomp_wdog();
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- arch_decomp_wdog();
- free_mem_ptr = (long) *ptr;
-}
-#else
-static void gzip_mark(void **ptr)
-{
-}
-
-static void gzip_release(void **ptr)
-{
-}
+#ifdef STANDALONE_DEBUG
+#define NO_INFLATE_MALLOC
#endif
/* ===========================================================================
Index: 2.6.14/arch/arm26/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/arm26/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/arm26/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Modified for ARM Linux by Russell King
*
* Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
@@ -52,8 +50,6 @@ static unsigned outcnt; /* bytes in out
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char input_data[];
extern char input_data_end[];
@@ -62,12 +58,6 @@ static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);
extern int end;
@@ -78,47 +68,8 @@ static ulg free_mem_ptr_end;
#include "../../../../lib/inflate.c"
-#ifndef STANDALONE_DEBUG
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_ptr_end)
- error("Out of memory");
- return p;
-}
-
-static void free(void *where)
-{ /* gzip_mark & gzip_release do the free */
-}
-
-static void gzip_mark(void **ptr)
-{
- arch_decomp_wdog();
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- arch_decomp_wdog();
- free_mem_ptr = (long) *ptr;
-}
-#else
-static void gzip_mark(void **ptr)
-{
-}
-
-static void gzip_release(void **ptr)
-{
-}
+#ifdef STANDALONE_DEBUG
+#define NO_INFLATE_MALLOC
#endif
/* ===========================================================================
Index: 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/cris/arch-v10/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -6,7 +6,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
*
@@ -51,57 +50,22 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char *input_data; /* lives in head.S */
static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
static void puts(const char *);
/* the "heap" is put directly after the BSS ends, at end */
extern int end;
static long free_mem_ptr = (long)&end;
-
-#include "../../../../../lib/inflate.c"
-
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
+static long free_mem_end_ptr = 0xffffffff;
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
+#include "../../../../../lib/inflate.c"
/* decompressor info and error messages to serial console */
Index: 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/cris/arch-v32/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -6,7 +6,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* adoptation for Linux/CRIS Axis Communications AB, 1999
*
@@ -53,8 +52,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char *input_data; /* lives in head.S */
@@ -62,49 +59,16 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);
/* the "heap" is put directly after the BSS ends, at end */
extern int _end;
static long free_mem_ptr = (long)&_end;
+static long free_mem_end_ptr = 0xffffffff;
#include "../../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* decompressor info and error messages to serial console */
static inline void
Index: 2.6.14/arch/i386/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/i386/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/i386/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,7 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
*/
@@ -43,9 +42,7 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
/*
* This is set up by the setup-routine at boot-time
*/
@@ -64,9 +61,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-static void *malloc(int size);
-static void free(void *where);
-
static void putstr(const char *);
extern int end;
@@ -91,38 +85,6 @@ static void * xquad_portio = NULL;
#include "../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
static void scroll(void)
{
int i;
Index: 2.6.14/arch/m32r/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/m32r/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/m32r/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* 2003-02-12: Support M32R by Takeo Takahashi
@@ -38,8 +36,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
static unsigned char *input_data;
static int input_len;
@@ -50,9 +46,6 @@ static unsigned long output_ptr = 0;
#include "m32r_sio.c"
-static void *malloc(int size);
-static void free(void *where);
-
static unsigned long free_mem_ptr;
static unsigned long free_mem_end_ptr;
@@ -60,38 +53,6 @@ static unsigned long free_mem_end_ptr;
#include "../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr == 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
Index: 2.6.14/arch/sh/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/sh/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SH by Stuart Menefy, Aug 1999
*
* Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
@@ -40,8 +38,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char input_data[];
extern int input_len;
@@ -50,12 +46,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
int puts(const char *);
extern int _text; /* Defined in vmlinux.lds.S */
@@ -67,38 +57,6 @@ static unsigned long free_mem_end_ptr;
#include "../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr == 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
#ifdef CONFIG_SH_STANDARD_BIOS
size_t strlen(const char *s)
{
Index: 2.6.14/arch/sh64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/sh64/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/sh64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,8 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- *
* Adapted for SHmedia from sh by Stuart Menefy, May 2002
*/
@@ -40,8 +38,6 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
extern char input_data[];
extern int input_len;
@@ -50,12 +46,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-static void *malloc(int size);
-static void free(void *where);
-static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
static void puts(const char *);
extern int _text; /* Defined in vmlinux.lds.S */
@@ -67,40 +57,6 @@ static unsigned long free_mem_end_ptr;
#include "../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size < 0)
- error("Malloc error\n");
- if (free_mem_ptr == 0)
- error("Memory error\n");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *) free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("\nOut of memory\n");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
void puts(const char *s)
{
}
Index: 2.6.14/arch/x86_64/boot/compressed/misc.c
===================================================================
--- 2.6.14.orig/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/arch/x86_64/boot/compressed/misc.c 2005-10-28 22:04:13.000000000 -0700
@@ -4,7 +4,6 @@
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
- * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
* puts by Nick Holloway 1993, better puts by Martin Mares 1995
* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
*/
@@ -36,9 +35,7 @@ static unsigned outcnt = 0; /* bytes in
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
-static void gzip_mark(void **);
-static void gzip_release(void **);
-
+
/*
* This is set up by the setup-routine at boot-time
*/
@@ -57,9 +54,6 @@ static long bytes_out = 0;
static uch *output_data;
static unsigned long output_ptr = 0;
-static void *malloc(int size);
-static void free(void *where);
-
static void putstr(const char *);
extern int end;
@@ -80,38 +74,6 @@ static int lines, cols;
#include "../../../../lib/inflate.c"
-static void *malloc(int size)
-{
- void *p;
-
- if (size <0) error("Malloc error");
- if (free_mem_ptr <= 0) error("Memory error");
-
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
-
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
-
- if (free_mem_ptr >= free_mem_end_ptr)
- error("Out of memory");
-
- return p;
-}
-
-static void free(void *where)
-{ /* Don't care */
-}
-
-static void gzip_mark(void **ptr)
-{
- *ptr = (void *) free_mem_ptr;
-}
-
-static void gzip_release(void **ptr)
-{
- free_mem_ptr = (long) *ptr;
-}
-
static void scroll(void)
{
int i;
Index: 2.6.14/init/do_mounts_rd.c
===================================================================
--- 2.6.14.orig/init/do_mounts_rd.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/init/do_mounts_rd.c 2005-10-28 22:04:13.000000000 -0700
@@ -298,32 +298,11 @@ static int crd_infd, crd_outfd;
static int __init fill_inbuf(void);
static void __init flush_window(void);
-static void __init *malloc(size_t size);
-static void __init free(void *where);
static void __init error(char *m);
-static void __init gzip_mark(void **);
-static void __init gzip_release(void **);
-#include "../lib/inflate.c"
-
-static void __init *malloc(size_t size)
-{
- return kmalloc(size, GFP_KERNEL);
-}
-
-static void __init free(void *where)
-{
- kfree(where);
-}
-
-static void __init gzip_mark(void **ptr)
-{
-}
-
-static void __init gzip_release(void **ptr)
-{
-}
+#define NO_INFLATE_MALLOC
+#include "../lib/inflate.c"
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
Index: 2.6.14/init/initramfs.c
===================================================================
--- 2.6.14.orig/init/initramfs.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/init/initramfs.c 2005-10-28 22:04:13.000000000 -0700
@@ -14,16 +14,6 @@ static void __init error(char *x)
message = x;
}
-static void __init *malloc(size_t size)
-{
- return kmalloc(size, GFP_KERNEL);
-}
-
-static void __init free(void *where)
-{
- kfree(where);
-}
-
/* link hash */
static __initdata struct hash {
@@ -51,7 +41,7 @@ static char __init *find_link(int major,
continue;
return (*p)->name;
}
- q = (struct hash *)malloc(sizeof(struct hash));
+ q = kmalloc(sizeof(struct hash), GFP_KERNEL);
if (!q)
panic("can't allocate link hash entry");
q->ino = ino;
@@ -70,7 +60,7 @@ static void __init free_hash(void)
while (*p) {
q = *p;
*p = q->next;
- free(q);
+ kfree(q);
}
}
}
@@ -364,18 +354,10 @@ static long bytes_out;
static void __init flush_window(void);
static void __init error(char *m);
-static void __init gzip_mark(void **);
-static void __init gzip_release(void **);
-#include "../lib/inflate.c"
+#define NO_INFLATE_MALLOC
-static void __init gzip_mark(void **ptr)
-{
-}
-
-static void __init gzip_release(void **ptr)
-{
-}
+#include "../lib/inflate.c"
/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
@@ -402,10 +384,10 @@ static char * __init unpack_to_rootfs(ch
{
int written;
dry_run = check_only;
- header_buf = malloc(110);
- symlink_buf = malloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1);
- name_buf = malloc(N_ALIGN(PATH_MAX));
- window = malloc(WSIZE);
+ header_buf = kmalloc(110, GFP_KERNEL);
+ symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
+ name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
+ window = kmalloc(WSIZE, GFP_KERNEL);
if (!window || !header_buf || !symlink_buf || !name_buf)
panic("can't allocate buffers");
state = Start;
@@ -441,10 +423,10 @@ static char * __init unpack_to_rootfs(ch
buf += inptr;
len -= inptr;
}
- free(window);
- free(name_buf);
- free(symlink_buf);
- free(header_buf);
+ kfree(window);
+ kfree(name_buf);
+ kfree(symlink_buf);
+ kfree(header_buf);
return message;
}
Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c 2005-10-28 22:03:58.000000000 -0700
+++ 2.6.14/lib/inflate.c 2005-10-28 22:04:13.000000000 -0700
@@ -109,6 +109,46 @@
#include <asm/types.h>
+#ifndef NO_INFLATE_MALLOC
+/* A trivial malloc implementation, adapted from
+ * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
+ */
+
+static unsigned long malloc_ptr;
+static int malloc_count;
+
+static void *malloc(int size)
+{
+ void *p;
+
+ if (size <0)
+ error("Malloc error");
+ if (!malloc_ptr)
+ malloc_ptr = free_mem_ptr;
+
+ malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
+
+ p = (void *)malloc_ptr;
+ malloc_ptr += size;
+
+ if (malloc_ptr >= free_mem_end_ptr)
+ error("Out of memory");
+
+ malloc_count++;
+ return p;
+}
+
+static void free(void *where)
+{
+ malloc_count--;
+ if (!malloc_count)
+ malloc_ptr = free_mem_ptr;
+}
+#else
+#define malloc(a) kmalloc(a, GFP_KERNEL)
+#define free(a) kfree(a)
+#endif
+
static u32 crc_32_tab[256];
static u32 crc; /* dummy var until users get cleaned up */
#define CRCPOLY_LE 0xedb88320
@@ -895,16 +935,12 @@ static int INIT inflate(struct iostate *
{
int e; /* last block flag */
int r; /* result code */
- void *ptr;
/* decompress until the last block */
do {
- gzip_mark(&ptr);
- if ((r = inflate_block(io, &e))) {
- gzip_release(&ptr);
+ r = inflate_block(io, &e);
+ if (r)
return r;
- }
- gzip_release(&ptr);
} while (!e);
popbytes(io);
next prev parent reply other threads:[~2005-10-31 21:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-31 20:54 [PATCH 1/20] inflate: lindent and manual formatting changes Matt Mackall
2005-10-31 20:54 ` [PATCH 2/20] inflate: kill legacy bits Matt Mackall
2005-10-31 20:54 ` [PATCH 3/20] inflate: clean up input logic Matt Mackall
2005-10-31 20:54 ` [PATCH 4/20] inflate: start moving globals into iostate Matt Mackall
2005-10-31 20:54 ` [PATCH 5/20] inflate: cleanup Huffman table code Matt Mackall
2005-10-31 20:54 ` [PATCH 6/20] inflate: internalize CRC calculation, cleanup table calculation Matt Mackall
2005-10-31 20:54 ` [PATCH 7/20] inflate: eliminate memzero usage Matt Mackall
2005-10-31 20:54 ` [PATCH 8/20] inflate: (arch) kill unneeded declarations Matt Mackall
2005-10-31 20:54 ` Matt Mackall [this message]
2005-10-31 20:54 ` [PATCH 10/20] inflate: (arch) kill external CRC calculation Matt Mackall
2005-10-31 20:54 ` [PATCH 11/20] inflate: (arch) kill get_byte Matt Mackall
2005-10-31 20:54 ` [PATCH 12/20] inflate: internalize (arch) most of the output window handling Matt Mackall
2005-10-31 20:54 ` [PATCH 13/20] inflate: (arch) kill silly zlib typedefs Matt Mackall
2005-10-31 20:54 ` [PATCH 14/20] inflate: (arch) use an error callback rather than a global Matt Mackall
2005-10-31 20:54 ` [PATCH 15/20] inflate: (arch) tidy user declarations Matt Mackall
2005-10-31 20:54 ` [PATCH 16/20] inflate: remove legacy DEBG macros Matt Mackall
2005-10-31 20:54 ` [PATCH 17/20] inflate: mark some arrays as initdata Matt Mackall
2005-10-31 20:54 ` [PATCH 18/20] inflate: minor const changes Matt Mackall
2005-10-31 20:54 ` [PATCH 19/20] inflate: (arch) use proper linking Matt Mackall
2005-10-31 20:54 ` [PATCH 20/20] inflate: make in-core inflate share common CRC Matt Mackall
2005-10-31 22:45 ` [PATCH 19/20] inflate: (arch) use proper linking Russell King
2005-10-31 23:02 ` Matt Mackall
2005-10-31 23:13 ` Russell King
2005-10-31 22:43 ` [PATCH 17/20] inflate: mark some arrays as initdata Russell King
2005-10-31 22:57 ` Matt Mackall
2005-10-31 23:10 ` Russell King
2005-10-31 23:11 ` Matt Mackall
2005-10-31 23:36 ` Russell King
2005-10-31 21:05 ` [PATCH 13/20] inflate: (arch) kill silly zlib typedefs Geert Uytterhoeven
2005-10-31 21:14 ` Matt Mackall
2005-11-01 6:53 ` Willy Tarreau
2005-11-01 7:50 ` Geert Uytterhoeven
2005-11-01 8:57 ` Willy Tarreau
2005-11-01 11:27 ` Geert Uytterhoeven
2005-11-08 6:05 ` Miles Bader
2005-11-08 6:18 ` Willy Tarreau
2005-11-01 0:24 ` [PATCH 1/20] inflate: lindent and manual formatting changes Paul Mackerras
2005-11-01 1:39 ` Matt Mackall
2005-11-01 7:50 ` Rob Landley
2005-11-01 18:28 ` Oops! Forgot [PATCH 0/20] inflate cleanups Matt Mackall
-- strict thread matches above, loose matches on Subject: below --
2005-12-22 18:26 [PATCH 8/20] inflate: (arch) kill unneeded declarations Matt Mackall
2005-12-22 18:26 ` [PATCH 9/20] inflate: (arch) refactor inflate malloc code Matt Mackall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10.196662837@selenic.com \
--to=mpm@selenic.com \
--cc=akpm@osdl.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox