Improve error code returns

This commit is contained in:
Tushar Gohad 2015-03-08 01:54:33 -07:00
parent 688ed3260d
commit 814e1a53d6
2 changed files with 21 additions and 17 deletions

View File

@ -246,7 +246,7 @@ int liberasurecode_instance_create(const ec_backend_id_t id,
ec_backend_t instance = NULL; ec_backend_t instance = NULL;
struct ec_backend_args bargs; struct ec_backend_args bargs;
if (!args) if (!args)
return -1; return -EINVALIDPARAMS;
if (id >= EC_BACKENDS_MAX) if (id >= EC_BACKENDS_MAX)
return -EBACKENDNOTSUPP; return -EBACKENDNOTSUPP;
@ -388,29 +388,29 @@ int liberasurecode_encode(int desc,
if (orig_data == NULL) { if (orig_data == NULL) {
log_error("Pointer to data buffer is null!"); log_error("Pointer to data buffer is null!");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (orig_data_size <= 0) { if (orig_data_size <= 0) {
log_error("Size of data to encode must be a positive value"); log_error("Size of data to encode must be a positive value");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (encoded_data == NULL) { if (encoded_data == NULL) {
log_error("Pointer to encoded data buffers is null!"); log_error("Pointer to encoded data buffers is null!");
return -1; return -EINVALIDPARAMS;
} }
if (encoded_parity == NULL) { if (encoded_parity == NULL) {
log_error("Pointer to encoded parity buffers is null!"); log_error("Pointer to encoded parity buffers is null!");
return -1; return -EINVALIDPARAMS;
} }
if (fragment_len == NULL) { if (fragment_len == NULL) {
log_error("Pointer to fragment length is null!"); log_error("Pointer to fragment length is null!");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
@ -538,19 +538,19 @@ int liberasurecode_decode(int desc,
if (NULL == available_fragments) { if (NULL == available_fragments) {
log_error("Pointer to encoded fragments buffer is null!"); log_error("Pointer to encoded fragments buffer is null!");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (NULL == out_data) { if (NULL == out_data) {
log_error("Pointer to decoded data buffer is null!"); log_error("Pointer to decoded data buffer is null!");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (NULL == out_data_len) { if (NULL == out_data_len) {
log_error("Pointer to decoded data length variable is null!"); log_error("Pointer to decoded data length variable is null!");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
@ -747,13 +747,13 @@ int liberasurecode_reconstruct_fragment(int desc,
if (NULL == available_fragments) { if (NULL == available_fragments) {
log_error("Can not reconstruct fragment, available fragments pointer is NULL"); log_error("Can not reconstruct fragment, available fragments pointer is NULL");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (NULL == out_fragment) { if (NULL == out_fragment) {
log_error("Can not reconstruct fragment, output fragment pointer is NULL"); log_error("Can not reconstruct fragment, output fragment pointer is NULL");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
@ -896,19 +896,19 @@ int liberasurecode_fragments_needed(int desc,
} }
if (NULL == fragments_to_reconstruct) { if (NULL == fragments_to_reconstruct) {
log_error("Unable to determine list of fragments needed, pointer to list of indexes to reconstruct is NULL."); log_error("Unable to determine list of fragments needed, pointer to list of indexes to reconstruct is NULL.");
ret = -1; ret = -EINVALIDPARAMS;
goto out_error; goto out_error;
} }
if (NULL == fragments_to_exclude) { if (NULL == fragments_to_exclude) {
log_error("Unable to determine list of fragments needed, pointer to list of fragments to exclude is NULL."); log_error("Unable to determine list of fragments needed, pointer to list of fragments to exclude is NULL.");
ret = -1; ret = -EINVALIDPARAMS;
goto out_error; goto out_error;
} }
if (NULL == fragments_needed) { if (NULL == fragments_needed) {
log_error("Unable to determine list of fragments needed, pointer to list of fragments to reconstruct is NULL."); log_error("Unable to determine list of fragments needed, pointer to list of fragments to reconstruct is NULL.");
ret = -1; ret = -EINVALIDPARAMS;
goto out_error; goto out_error;
} }
@ -943,13 +943,13 @@ int liberasurecode_get_fragment_metadata(char *fragment,
if (NULL == fragment) { if (NULL == fragment) {
log_error("Need valid fragment object to get metadata for"); log_error("Need valid fragment object to get metadata for");
ret = -1; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
if (NULL == fragment_metadata) { if (NULL == fragment_metadata) {
log_error("Need valid fragment_metadata object for return value"); log_error("Need valid fragment_metadata object for return value");
ret = -2; ret = -EINVALIDPARAMS;
goto out; goto out;
} }
@ -957,7 +957,7 @@ int liberasurecode_get_fragment_metadata(char *fragment,
fragment_hdr = (fragment_header_t *) fragment; fragment_hdr = (fragment_header_t *) fragment;
if (LIBERASURECODE_FRAG_HEADER_MAGIC != fragment_hdr->magic) { if (LIBERASURECODE_FRAG_HEADER_MAGIC != fragment_hdr->magic) {
log_error("Invalid fragment, illegal magic value"); log_error("Invalid fragment, illegal magic value");
ret = -2; ret = -EINVALIDPARAMS;
goto out; goto out;
} }

View File

@ -277,6 +277,7 @@ int fragments_to_string(int k, int m,
if (NULL == data) { if (NULL == data) {
log_error("Could not allocate buffer for data!!"); log_error("Could not allocate buffer for data!!");
ret = -ENOMEM;
goto out; goto out;
} }
@ -285,6 +286,7 @@ int fragments_to_string(int k, int m,
data_size = get_fragment_payload_size(fragments[i]); data_size = get_fragment_payload_size(fragments[i]);
if ((index < 0) || (data_size < 0)) { if ((index < 0) || (data_size < 0)) {
log_error("Invalid fragment header information!"); log_error("Invalid fragment header information!");
ret = -EINVALIDPARAMS;
goto out; goto out;
} }
@ -294,6 +296,7 @@ int fragments_to_string(int k, int m,
} else { } else {
if (get_orig_data_size(fragments[i]) != orig_data_size) { if (get_orig_data_size(fragments[i]) != orig_data_size) {
log_error("Inconsistent orig_data_size in fragment header!"); log_error("Inconsistent orig_data_size in fragment header!");
ret = -EINVALIDPARAMS;
goto out; goto out;
} }
} }
@ -323,6 +326,7 @@ int fragments_to_string(int k, int m,
internal_payload = (char *) get_aligned_buffer16(orig_data_size); internal_payload = (char *) get_aligned_buffer16(orig_data_size);
if (NULL == internal_payload) { if (NULL == internal_payload) {
log_error("Could not allocate buffer for decoded string!"); log_error("Could not allocate buffer for decoded string!");
ret = -ENOMEM;
goto out; goto out;
} }