diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h index 0c35411..81676ae 100644 --- a/include/linux/decompress/mm.h +++ b/include/linux/decompress/mm.h @@ -30,7 +30,7 @@ STATIC_RW_DATA unsigned long malloc_ptr; STATIC_RW_DATA int malloc_count; -static void *malloc(int size) +static __maybe_unused void *simple_malloc(int size) { void *p; @@ -51,15 +51,18 @@ return p; } -static void free(void *where) +static __maybe_unused void simple_free(void *where) { malloc_count--; if (!malloc_count) malloc_ptr = free_mem_ptr; } -#define large_malloc(a) malloc(a) -#define large_free(a) free(a) +#define large_malloc(a) simple_malloc(a) +#define large_free(a) simple_free(a) + +#define MALLOC simple_malloc +#define FREE simple_free #define INIT diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c index d5ea01a..47bd3db 100644 --- a/lib/decompress_inflate.c +++ b/lib/decompress_inflate.c @@ -13,6 +13,9 @@ #else /* STATIC */ /* initramfs et al: linked */ +#define MALLOC malloc +#define FREE free + #include #include #include @@ -49,7 +52,7 @@ rc = -1; if (flush) { out_len = 0x8000; /* 32 K */ - out_buf = malloc(out_len); + out_buf = MALLOC(out_len); } else { out_len = 0x7fffffff; /* no limit */ } @@ -61,7 +64,7 @@ if (buf) zbuf = buf; else { - zbuf = malloc(GZIP_IOBUF_SIZE); + zbuf = MALLOC(GZIP_IOBUF_SIZE); len = 0; } if (!zbuf) { @@ -69,13 +72,13 @@ goto gunzip_nomem2; } - strm = malloc(sizeof(*strm)); + strm = MALLOC(sizeof(*strm)); if (strm == NULL) { error("Out of memory while allocating z_stream"); goto gunzip_nomem3; } - strm->workspace = malloc(flush ? zlib_inflate_workspacesize() : + strm->workspace = MALLOC(flush ? zlib_inflate_workspacesize() : sizeof(struct inflate_state)); if (strm->workspace == NULL) { error("Out of memory while allocating workspace"); @@ -170,15 +173,15 @@ *pos = strm->next_in - zbuf+8; gunzip_5: - free(strm->workspace); + FREE(strm->workspace); gunzip_nomem4: - free(strm); + FREE(strm); gunzip_nomem3: if (!buf) - free(zbuf); + FREE(zbuf); gunzip_nomem2: if (flush) - free(out_buf); + FREE(out_buf); gunzip_nomem1: return rc; /* returns Z_OK (0) if successful */ } diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c index 0dfb08c..46a010a 100644 --- a/lib/decompress_unlz4.c +++ b/lib/decompress_unlz4.c @@ -15,6 +15,8 @@ #else #include #include +#define MALLOC malloc +#define FREE free #endif #include #include @@ -62,7 +64,7 @@ error("NULL output pointer and no flush function provided"); goto exit_0; } else { - outp = malloc(uncomp_chunksize); + outp = MALLOC(uncomp_chunksize); if (!outp) { error("Could not allocate output buffer"); goto exit_0; @@ -78,7 +80,7 @@ error("NULL input pointer and missing fill function"); goto exit_1; } else { - inp = malloc(lz4_compressbound(uncomp_chunksize)); + inp = MALLOC(lz4_compressbound(uncomp_chunksize)); if (!inp) { error("Could not allocate input buffer"); goto exit_1; @@ -171,10 +173,10 @@ ret = 0; exit_2: if (!input) - free(inp_start); + FREE(inp_start); exit_1: if (!output) - free(outp); + FREE(outp); exit_0: return ret; } diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c index 10ad42a..ad7f977 100644 --- a/lib/decompress_unlzo.c +++ b/lib/decompress_unlzo.c @@ -36,6 +36,8 @@ #include "lzo/lzo1x_decompress_safe.c" #else #include +#define MALLOC malloc +#define FREE free #endif #include @@ -126,7 +128,7 @@ error("NULL output pointer and no flush function provided"); goto exit; } else { - out_buf = malloc(LZO_BLOCK_SIZE); + out_buf = MALLOC(LZO_BLOCK_SIZE); if (!out_buf) { error("Could not allocate output buffer"); goto exit; @@ -142,7 +144,7 @@ error("NULL input pointer and missing fill function"); goto exit_1; } else { - in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE)); + in_buf = MALLOC(lzo1x_worst_compress(LZO_BLOCK_SIZE)); if (!in_buf) { error("Could not allocate input buffer"); goto exit_1; @@ -278,10 +280,10 @@ ret = 0; exit_2: if (!input) - free(in_buf_save); + FREE(in_buf_save); exit_1: if (!output) - free(out_buf); + FREE(out_buf); exit: return ret; } diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c index 1ddcee3..a7e2d33 100644 --- a/lib/decompress_unxz.c +++ b/lib/decompress_unxz.c @@ -109,6 +109,8 @@ #define XZ_EXTERN STATIC #ifndef XZ_PREBOOT +#define FREE free +#define MALLOC malloc # include # include #else @@ -258,14 +260,14 @@ b.out_size = (size_t)-1; } else { b.out_size = XZ_IOBUF_SIZE; - b.out = malloc(XZ_IOBUF_SIZE); + b.out = MALLOC(XZ_IOBUF_SIZE); if (b.out == NULL) goto error_alloc_out; } if (in == NULL) { must_free_in = true; - in = malloc(XZ_IOBUF_SIZE); + in = MALLOC(XZ_IOBUF_SIZE); if (in == NULL) goto error_alloc_in; } @@ -316,10 +318,10 @@ } while (ret == XZ_OK); if (must_free_in) - free(in); + FREE(in); if (flush != NULL) - free(b.out); + FREE(b.out); } if (in_used != NULL) @@ -359,7 +361,7 @@ error_alloc_in: if (flush != NULL) - free(b.out); + FREE(b.out); error_alloc_out: xz_dec_end(s); diff --git a/lib/xz/xz_dec_bcj.c b/lib/xz/xz_dec_bcj.c index a768e6d..d268adb 100644 --- a/lib/xz/xz_dec_bcj.c +++ b/lib/xz/xz_dec_bcj.c @@ -526,7 +526,7 @@ XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call) { - struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL); + struct xz_dec_bcj *s = MALLOC(sizeof(*s)); if (s != NULL) s->single_call = single_call; diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c index 08c3c80..87ffd95 100644 --- a/lib/xz/xz_dec_lzma2.c +++ b/lib/xz/xz_dec_lzma2.c @@ -1108,7 +1108,7 @@ XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode, uint32_t dict_max) { - struct xz_dec_lzma2 *s = kmalloc(sizeof(*s), GFP_KERNEL); + struct xz_dec_lzma2 *s = MALLOC(sizeof(*s)); if (s == NULL) return NULL; @@ -1116,9 +1116,9 @@ s->dict.size_max = dict_max; if (DEC_IS_PREALLOC(mode)) { - s->dict.buf = vmalloc(dict_max); + s->dict.buf = MALLOC(dict_max); if (s->dict.buf == NULL) { - kfree(s); + FREE(s); return NULL; } } else if (DEC_IS_DYNALLOC(mode)) { @@ -1146,8 +1146,8 @@ if (DEC_IS_DYNALLOC(s->dict.mode)) { if (s->dict.allocated < s->dict.size) { - vfree(s->dict.buf); - s->dict.buf = vmalloc(s->dict.size); + FREE(s->dict.buf); + s->dict.buf = MALLOC(s->dict.size); if (s->dict.buf == NULL) { s->dict.allocated = 0; return XZ_MEM_ERROR; @@ -1169,7 +1169,7 @@ XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s) { if (DEC_IS_MULTI(s->dict.mode)) - vfree(s->dict.buf); + FREE(s->dict.buf); - kfree(s); + FREE(s); } diff --git a/lib/xz/xz_dec_stream.c b/lib/xz/xz_dec_stream.c index ac809b1..fa1751d 100644 --- a/lib/xz/xz_dec_stream.c +++ b/lib/xz/xz_dec_stream.c @@ -769,7 +769,7 @@ XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max) { - struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL); + struct xz_dec *s = MALLOC(sizeof(*s)); if (s == NULL) return NULL; @@ -793,7 +793,7 @@ xz_dec_bcj_end(s->bcj); error_bcj: #endif - kfree(s); + FREE(s); return NULL; } @@ -816,6 +816,6 @@ #ifdef XZ_DEC_BCJ xz_dec_bcj_end(s->bcj); #endif - kfree(s); + FREE(s); } } diff --git a/lib/xz/xz_private.h b/lib/xz/xz_private.h index 99b8ade..85f7963 100644 --- a/lib/xz/xz_private.h +++ b/lib/xz/xz_private.h @@ -39,6 +39,8 @@ # endif # define memeq(a, b, size) (memcmp(a, b, size) == 0) # define memzero(buf, size) memset(buf, 0, size) +# define FREE free +# define MALLOC malloc # endif # define get_le32(p) le32_to_cpup((const uint32_t *)(p)) #else @@ -150,7 +152,7 @@ struct xz_buf *b); /* Free the memory allocated for the BCJ filters. */ -#define xz_dec_bcj_end(s) kfree(s) +#define xz_dec_bcj_end(s) FREE(s) #endif #endif diff --git a/lib/zlib_inflate/infutil.c b/lib/zlib_inflate/infutil.c index f452ba6..d976552 100644 --- a/lib/zlib_inflate/infutil.c +++ b/lib/zlib_inflate/infutil.c @@ -12,10 +12,10 @@ int rc; rc = -ENOMEM; - strm = kmalloc(sizeof(*strm), GFP_KERNEL); + strm = MALLOC(sizeof(*strm)); if (strm == NULL) goto gunzip_nomem1; - strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); + strm->workspace = MALLOC(zlib_inflate_workspacesize()); if (strm->workspace == NULL) goto gunzip_nomem2; @@ -39,9 +39,9 @@ } else rc = -EINVAL; - kfree(strm->workspace); + FREE(strm->workspace); gunzip_nomem2: - kfree(strm); + FREE(strm); gunzip_nomem1: return rc; /* returns Z_OK (0) if successful */ }