Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions os/compression/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refer to below style.

int decompress_block(unsigned char *out_buffer, long unsigned int *writesize, unsigned char *read_buffer, long unsigned int *size)
{
	int ret = ERROR;
#if CONFIG_COMPRESSION_TYPE == LZMA
	/* LZMA specific logic for decompression */
	*size -= (LZMA_PROPS_SIZE);
	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_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("LzmaUncompress is not SZ_OK 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("mz_uncompress is not Z_OK ret : %d\n", ret);
		if (ret == Z_BUF_ERROR) {
			return -ENOMEM;
		}
		return -EIO;
	}
#endif
	return OK;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for guide me a better style.

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;
}
11 changes: 6 additions & 5 deletions os/drivers/compression/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init is failed here but we can continue compress?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it.
It should return here.

filep->f_priv = data;
Expand All @@ -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:
Expand All @@ -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:
Expand Down