diff --git a/os/compression/compress.c b/os/compression/compress.c index f72a0860a5..0517cbaa04 100644 --- a/os/compression/compress.c +++ b/os/compression/compress.c @@ -106,29 +106,29 @@ int decompress_block(unsigned char *out_buffer, long unsigned int *writesize, un int read_size = *size; ret = LzmaUncompress(&out_buffer[0], (unsigned int *)writesize, &read_buffer[LZMA_PROPS_SIZE], (unsigned int *)size, &read_buffer[0], LZMA_PROPS_SIZE); - if (ret == SZ_ERROR_FAIL) { - bcmpdbg("Failure to decompress with LZMAUncompress API\n"); - ret = -ret; - } - else if (ret == SZ_OK && *size < read_size) { - bcmpdbg("Out buffer allocated is not sufficient, some inputs are still left to be uncompressed\n"); - ret = ENOMEM; - } - else if (ret == SZ_ERROR_INPUT_EOF) { - bcmpdbg("Decompressed successful with some output buffer left\n"); - ret = SZ_OK; + if (ret == SZ_OK) { + if (*size < read_size) { + bcmpdbg("Out buffer allocated is not sufficient, some inputs are still left to be uncompressed\n"); + return -ENOMEM; + } + return OK; + } else { + bcmpdbg("Failure to decompress with LZMA's uncompress API; ret = %d\n", ret); + if (ret == SZ_ERROR_INPUT_EOF) { + return OK; + } + return -EIO; } #elif CONFIG_COMPRESSION_TYPE == MINIZ /* Miniz specific logic for decompression */ ret = mz_uncompress(out_buffer, writesize, read_buffer, *size); if (ret != Z_OK) { bcmpdbg("Failure to decompress with Miniz's uncompress API; ret = %d\n", ret); - if (ret > 0) - ret = -ret; - else if (ret == Z_BUF_ERROR) { - ret = ENOMEM; + if (ret == Z_BUF_ERROR) { + return -ENOMEM; } - } + return -EIO; + } #endif - return ret; + return OK; } diff --git a/os/drivers/compression/compress.c b/os/drivers/compression/compress.c index 551742c9d4..9e4cf216bd 100644 --- a/os/drivers/compression/compress.c +++ b/os/drivers/compression/compress.c @@ -155,8 +155,9 @@ static int comp_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return -EINVAL; } ret = decompress_block(comp_info->output_buffer, &comp_info->output_size, comp_info->input_buffer, &comp_info->input_size); - if (ret == ENOMEM) { + if (ret == -ENOMEM) { bcmpdbg("Output buffer allocated is not sufficient\n"); + return ret; } case COMPIOC_FCOMP_INIT: if ((char *)arg == NULL) { @@ -179,9 +180,8 @@ static int comp_ioctl(FAR struct file *filep, int cmd, unsigned long arg) bcmpdbg("Another file decompression is in process\n"); close(data->fd); free(data); - return ret; } - ret = ERROR; + return ret; } DEBUGASSERT(filep); filep->f_priv = data; @@ -193,7 +193,7 @@ static int comp_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ret = data->compression_header->binary_size; if (ret <= 0) { bcmpdbg("Failed to get buffer size = %d\n", ret); - ret = ERROR; + return -EBADF; } break; case COMPIOC_FCOMP_DECOMPRESS: @@ -205,7 +205,8 @@ static int comp_ioctl(FAR struct file *filep, int cmd, unsigned long arg) size = compress_read(data->fd, 0, (uint8_t *)arg, data->compression_header->binary_size, 0); ret = OK; if (size != data->compression_header->binary_size) { - ret = ERROR; + bcmpdbg("Compress header size mismatch"); + return -EINVAL; } break; case COMPIOC_FCOMP_DEINIT: