| #include <linux/vmalloc.h> |
| /* Utility function: initialize zlib, unpack binary blob, clean up zlib, |
| * return len or negative error code. |
| int zlib_inflate_blob(void *gunzip_buf, unsigned int sz, |
| const void *buf, unsigned int len) |
| strm = kmalloc(sizeof(*strm), GFP_KERNEL); |
| strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); |
| if (strm->workspace == NULL) |
| /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename) |
| * expected to be stripped from input |
| strm->next_out = gunzip_buf; |
| rc = zlib_inflateInit2(strm, -MAX_WBITS); |
| rc = zlib_inflate(strm, Z_FINISH); |
| /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */ |
| rc = sz - strm->avail_out; |
| return rc; /* returns Z_OK (0) if successful */ |