diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index b7702ca4731..3352a955a63 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -261,54 +261,6 @@ struct section { static unsigned num_sections; static struct section sections[MAX_SECTIONS]; -static int zlib_inflate(uint32_t **ptr, int len) -{ - struct z_stream_s zstream; - void *out; - const uint32_t out_size = 128*4096; /* approximate obj size */ - - memset(&zstream, 0, sizeof(zstream)); - - zstream.next_in = (unsigned char *)*ptr; - zstream.avail_in = 4*len; - - if (inflateInit(&zstream) != Z_OK) - return 0; - - out = malloc(out_size); - zstream.next_out = out; - zstream.avail_out = out_size; - - do { - switch (inflate(&zstream, Z_SYNC_FLUSH)) { - case Z_STREAM_END: - goto end; - case Z_OK: - break; - default: - inflateEnd(&zstream); - return 0; - } - - if (zstream.avail_out) - break; - - out = realloc(out, 2*zstream.total_out); - if (out == NULL) { - inflateEnd(&zstream); - return 0; - } - - zstream.next_out = (unsigned char *)out + zstream.total_out; - zstream.avail_out = zstream.total_out; - } while (1); - end: - inflateEnd(&zstream); - free(*ptr); - *ptr = out; - return zstream.total_out / 4; -} - static int ascii85_decode(const char *in, uint32_t **out, bool inflate) { int len = 0, size = 1024; diff --git a/src/intel/tools/error2aub.c b/src/intel/tools/error2aub.c index 19e09aede3f..832c625a26a 100644 --- a/src/intel/tools/error2aub.c +++ b/src/intel/tools/error2aub.c @@ -42,54 +42,6 @@ #define fail(...) fail_if(true, __VA_ARGS__) -static int zlib_inflate(uint32_t **ptr, int len) -{ - struct z_stream_s zstream; - void *out; - const uint32_t out_size = 128*4096; /* approximate obj size */ - - memset(&zstream, 0, sizeof(zstream)); - - zstream.next_in = (unsigned char *)*ptr; - zstream.avail_in = 4*len; - - if (inflateInit(&zstream) != Z_OK) - return 0; - - out = malloc(out_size); - zstream.next_out = out; - zstream.avail_out = out_size; - - do { - switch (inflate(&zstream, Z_SYNC_FLUSH)) { - case Z_STREAM_END: - goto end; - case Z_OK: - break; - default: - inflateEnd(&zstream); - return 0; - } - - if (zstream.avail_out) - break; - - out = realloc(out, 2*zstream.total_out); - if (out == NULL) { - inflateEnd(&zstream); - return 0; - } - - zstream.next_out = (unsigned char *)out + zstream.total_out; - zstream.avail_out = zstream.total_out; - } while (1); - end: - inflateEnd(&zstream); - free(*ptr); - *ptr = out; - return zstream.total_out / 4; -} - static int ascii85_decode(const char *in, uint32_t **out, bool inflate) { int len = 0, size = 1024; diff --git a/src/intel/tools/error2hangdump.c b/src/intel/tools/error2hangdump.c index 8b571c363ea..a337d6a51c1 100644 --- a/src/intel/tools/error2hangdump.c +++ b/src/intel/tools/error2hangdump.c @@ -41,54 +41,6 @@ #define XE_KMD_ERROR_DUMP_IDENTIFIER "**** Xe Device Coredump ****" -static int zlib_inflate(uint32_t **ptr, int len) -{ - struct z_stream_s zstream; - void *out; - const uint32_t out_size = 128*4096; /* approximate obj size */ - - memset(&zstream, 0, sizeof(zstream)); - - zstream.next_in = (unsigned char *)*ptr; - zstream.avail_in = 4*len; - - if (inflateInit(&zstream) != Z_OK) - return 0; - - out = malloc(out_size); - zstream.next_out = out; - zstream.avail_out = out_size; - - do { - switch (inflate(&zstream, Z_SYNC_FLUSH)) { - case Z_STREAM_END: - goto end; - case Z_OK: - break; - default: - inflateEnd(&zstream); - return 0; - } - - if (zstream.avail_out) - break; - - out = realloc(out, 2*zstream.total_out); - if (out == NULL) { - inflateEnd(&zstream); - return 0; - } - - zstream.next_out = (unsigned char *)out + zstream.total_out; - zstream.avail_out = zstream.total_out; - } while (1); - end: - inflateEnd(&zstream); - free(*ptr); - *ptr = out; - return zstream.total_out / 4; -} - static int ascii85_decode(const char *in, uint32_t **out, bool inflate) { int len = 0, size = 1024; diff --git a/src/intel/tools/error_decode_lib.c b/src/intel/tools/error_decode_lib.c index 2f2b240dadc..35b8657cf3d 100644 --- a/src/intel/tools/error_decode_lib.c +++ b/src/intel/tools/error_decode_lib.c @@ -1,10 +1,14 @@ /* - * Copyright 2024 Intel Corporation + * Copyright 2024-2025 Intel Corporation * SPDX-License-Identifier: MIT */ #include "error_decode_lib.h" +#include +#include +#include + const char * ascii85_decode_char(const char *in, uint32_t *v) { @@ -23,3 +27,52 @@ ascii85_decode_char(const char *in, uint32_t *v) return in; } + +int zlib_inflate(uint32_t **ptr, int len) +{ + struct z_stream_s zstream; + void *out; + const uint32_t out_size = 128*4096; /* approximate obj size */ + + memset(&zstream, 0, sizeof(zstream)); + + zstream.next_in = (unsigned char *)*ptr; + zstream.avail_in = 4*len; + + if (inflateInit(&zstream) != Z_OK) + return 0; + + out = malloc(out_size); + zstream.next_out = out; + zstream.avail_out = out_size; + + do { + switch (inflate(&zstream, Z_SYNC_FLUSH)) { + case Z_STREAM_END: + goto end; + case Z_OK: + break; + default: + free(out); + inflateEnd(&zstream); + return 0; + } + + if (zstream.avail_out) + break; + + out = realloc(out, 2*zstream.total_out); + if (out == NULL) { + inflateEnd(&zstream); + return 0; + } + + zstream.next_out = (unsigned char *)out + zstream.total_out; + zstream.avail_out = zstream.total_out; + } while (1); + end: + inflateEnd(&zstream); + free(*ptr); + *ptr = out; + return zstream.total_out / 4; +} diff --git a/src/intel/tools/error_decode_lib.h b/src/intel/tools/error_decode_lib.h index 357787edc71..431c81480bb 100644 --- a/src/intel/tools/error_decode_lib.h +++ b/src/intel/tools/error_decode_lib.h @@ -1,5 +1,5 @@ /* - * Copyright 2024 Intel Corporation + * Copyright 2024-2025 Intel Corporation * SPDX-License-Identifier: MIT */ @@ -8,3 +8,5 @@ #include const char *ascii85_decode_char(const char *in, uint32_t *v); + +int zlib_inflate(uint32_t **ptr, int len);