[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xen/gzip: Remove custom memory allocator



commit 052cf1dcdfb8563840d4a61843327687e7e64d73
Author:     Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
AuthorDate: Wed Apr 17 10:37:13 2024 -0400
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu Apr 18 20:43:11 2024 +0100

    xen/gzip: Remove custom memory allocator
    
    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
    with xmalloc_bytes().
    
    Signed-off-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/common/gzip/gunzip.c  | 17 ++---------------
 xen/common/gzip/inflate.c | 46 ----------------------------------------------
 2 files changed, 2 insertions(+), 61 deletions(-)

diff --git a/xen/common/gzip/gunzip.c b/xen/common/gzip/gunzip.c
index fdccaa9159..53cee9ee17 100644
--- a/xen/common/gzip/gunzip.c
+++ b/xen/common/gzip/gunzip.c
@@ -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
 
@@ -22,6 +17,8 @@ static unsigned int __initdata inptr;
 /* Bytes in output buffer: */
 static unsigned int __initdata outcnt;
 
+#define malloc(a)       xmalloc_bytes(a)
+#define free(a)         xfree(a)
 #define memzero(s, n)   memset((s), 0, (n))
 
 typedef unsigned char   uch;
@@ -107,14 +104,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;
@@ -131,7 +120,5 @@ __init int perform_gunzip(char *output, char *image, 
unsigned long image_len)
         rc = 0;
     }
 
-    free_xenheap_pages((void *)free_mem_ptr, HEAPORDER);
-
     return rc;
 }
diff --git a/xen/common/gzip/inflate.c b/xen/common/gzip/inflate.c
index fc9b466e0c..f2f953e80e 100644
--- a/xen/common/gzip/inflate.c
+++ b/xen/common/gzip/inflate.c
@@ -225,52 +225,6 @@ static const ush mask_bits[] = {
 #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
 #define DUMPBITS(n) {b>>=(n);k-=(n);}
 
-#ifndef NO_INFLATE_MALLOC
-/* A trivial malloc implementation, adapted from
- *  malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- */
-
-static unsigned long __initdata malloc_ptr;
-static int __initdata malloc_count;
-
-static void __init init_allocator(void)
-{
-    malloc_ptr = free_mem_ptr;
-    malloc_count = 0;
-}
-
-static void *__init 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 (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
-        error("Out of memory");
-
-    malloc_count++;
-    return p;
-}
-
-static void __init 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
-
 /*
    Huffman code decoding is performed using a multi-level table lookup.
    The fastest way to decode is to simply build a lookup table whose
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.