-
Notifications
You must be signed in to change notification settings - Fork 618
os/drivers: Modify to return errno from compression ioctl #6911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/drivers: Modify to return errno from compression ioctl #6911
Conversation
os/drivers/compression/compress.c
Outdated
| ret = decompress_block(comp_info->output_buffer, &comp_info->output_size, comp_info->input_buffer, &comp_info->input_size); | ||
| if (ret == ENOMEM) { | ||
| bcmpdbg("Output buffer allocated is not sufficient\n"); | ||
| return -ENOMEM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think decompress_block should return one of negative value. You should consider below.
- LzmaDecode returns one of below.
#define SZ_OK 0
#define SZ_ERROR_DATA 1
#define SZ_ERROR_MEM 2
#define SZ_ERROR_CRC 3
#define SZ_ERROR_UNSUPPORTED 4
#define SZ_ERROR_PARAM 5
#define SZ_ERROR_INPUT_EOF 6
#define SZ_ERROR_OUTPUT_EOF 7
#define SZ_ERROR_READ 8
#define SZ_ERROR_WRITE 9
#define SZ_ERROR_PROGRESS 10
#define SZ_ERROR_FAIL 11
#define SZ_ERROR_THREAD 12
#define SZ_ERROR_ARCHIVE 16
#define SZ_ERROR_NO_ARCHIVE 17
In this case, will you convert above type to errno in errno.h? for example, SZ_ERROR_UNSUPPORTED can be converted to EINVAL. Or you can convert entire of error as EIO and put some log to distinguish error
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 == Z_BUF_ERROR) {
ret = -ENOMEM;
} else {
ret = -EIO;
}
}
- 'decompress_block' is part of os, it located in os/compression. Hence it should not return SZ_OK or something.
it should return OK or one of errno.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add one more commit to fix that.
os/drivers/compression/compress.c
Outdated
| close(data->fd); | ||
| free(data); | ||
| return ret; | ||
| return -EBUSY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ret;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
I incorrectly thought to ret is EBUSY here.
| } | ||
| ret = ERROR; | ||
| } | ||
| DEBUGASSERT(filep); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
os/drivers/compression/compress.c
Outdated
| if (ret <= 0) { | ||
| bcmpdbg("Failed to get buffer size = %d\n", ret); | ||
| ret = ERROR; | ||
| return -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-EINVAL means that argument is wrong.
But this error means that file doesn't include compression header in its priv data area.
Hence I think EBADF(bad file descriptor) is most proper errno
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
2ad16a5 to
78be917
Compare
Return proper error codes instead of ERROR Add error logging for COMPIOC_FCOMP_DECOMPRESS case Signed-off-by: seokhun-eom <[email protected]>
78be917 to
0258ab3
Compare
| 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; | ||
| if (ret == SZ_OK) { |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
Previous, LzmaUncompress return code cannot be mapped to proper errno. standardize decompress_block to return OK, -EIO, or -ENOMEM. Add error logging with the API return value. Signed-off-by: seokhun-eom <[email protected]>
53d2290 to
61c62d5
Compare
|
This is violence of file operation, actually ioctl never be called without open. I think init / deinit can be handled in open/close |
Thank you for your comment. |
I made a PR for implement comp_open comp_close. |
compress ioctl
Return proper error codes instead of ERROR
Add error logging for COMPIOC_FCOMP_DECOMPRESS case.
decompress_block
Previous, LzmaUncompress return code cannot be mapped to proper errno.
standardize decompress_block to return OK, -EIO, or -ENOMEM.
Add error logging with the API return value.