Fixed some bugs found by the coverity tool

Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
This commit is contained in:
Michal Rakowski 2019-09-13 16:10:40 +02:00
parent 0391fc17b7
commit 83e23c5593
8 changed files with 33 additions and 20 deletions

View File

@ -68,6 +68,7 @@ static void _ocf_discard_core_complete(struct ocf_io *io, int error)
static int _ocf_discard_core(struct ocf_request *req)
{
struct ocf_io *io;
int err;
io = ocf_volume_new_io(&req->core->volume, req->io_queue,
SECTORS_TO_BYTES(req->discard.sector),
@ -79,7 +80,11 @@ static int _ocf_discard_core(struct ocf_request *req)
}
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete);
ocf_io_set_data(io, req->data, 0);
err = ocf_io_set_data(io, req->data, 0);
if (err) {
_ocf_discard_complete_req(req, err);
return err;
}
ocf_volume_submit_discard(io);

View File

@ -774,9 +774,16 @@ int ocf_metadata_query_cores_segment_io(
uint32_t offset;
uint32_t io_count;
uint32_t i;
uint32_t max_pages_per_io = ocf_volume_get_max_io_size(volume) /
PAGE_SIZE;
uint32_t max_pages_per_io;
int err = 0;
unsigned int max_io_size = ocf_volume_get_max_io_size(volume);
if (!max_io_size) {
err = -OCF_ERR_INVAL;
goto exit;
}
max_pages_per_io = max_io_size / PAGE_SIZE;
/* Allocate data */
segment_data->data = ctx_data_alloc(owner,

View File

@ -373,7 +373,7 @@ static int _raw_ram_flush_do_asynch_fill(ocf_cache_t cache,
uint32_t raw_page;
struct _raw_ram_flush_ctx *ctx = context;
struct ocf_metadata_raw *raw = NULL;
uint64_t size;
uint32_t size;
ENV_BUG_ON(!ctx);

View File

@ -571,9 +571,14 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
return -OCF_ERR_NO_MEM;
}
if (!ocf_refcnt_inc(&cache->refcnt.cache)){
env_mutex_destroy(&cache->flush_mutex);
env_vfree(cache);
return -OCF_ERR_START_CACHE_FAIL;
}
INIT_LIST_HEAD(&cache->list);
list_add_tail(&cache->list, &params->ctx->caches);
ocf_refcnt_inc(&cache->refcnt.cache);
cache->owner = params->ctx;
/* start with freezed metadata ref counter to indicate detached device*/
@ -1654,14 +1659,8 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
ocf_cache_log(*cache, log_info, "Successfully added\n");
ocf_cache_log(*cache, log_info, "Cache mode : %s\n",
_ocf_cache_mode_get_name(ocf_cache_get_mode(*cache)));
} else {
if (cfg->name) {
ocf_log(ctx, log_err, "Inserting cache %s failed\n",
cfg->name);
} else {
ocf_log(ctx, log_err, "Inserting cache failed\n");
}
}
} else
ocf_log(ctx, log_err, "%s: Inserting cache failed\n", cfg->name);
return result;
}

View File

@ -32,7 +32,7 @@ static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
{
int result;
if (!uuid->data || !muuid->data)
if (!uuid->data)
return -EINVAL;
if (uuid->size > sizeof(muuid->data))

View File

@ -277,8 +277,8 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
OCF_METADATA_LOCK_WR();
result = env_memcpy(old_config, sizeof(&cache->user_parts),
cache->user_parts, sizeof(&cache->user_parts));
result = env_memcpy(old_config, sizeof(cache->user_parts),
cache->user_parts, sizeof(cache->user_parts));
if (result)
goto out_cpy;
@ -295,8 +295,8 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
out_edit:
if (result) {
ENV_BUG_ON(env_memcpy(cache->user_parts, sizeof(&cache->user_parts),
old_config, sizeof(&cache->user_parts)));
ENV_BUG_ON(env_memcpy(cache->user_parts, sizeof(cache->user_parts),
old_config, sizeof(cache->user_parts)));
}
out_cpy:

View File

@ -73,13 +73,15 @@ void ocf_volume_type_deinit(struct ocf_volume_type *type)
int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid, bool uuid_copy)
{
uint32_t priv_size = type->properties->volume_priv_size;
uint32_t priv_size;
void *data;
int ret;
if (!volume || !type)
return -OCF_ERR_INVAL;
priv_size = type->properties->volume_priv_size;
volume->opened = false;
volume->type = type;

View File

@ -64,7 +64,7 @@ static int ocf_part_lst_cmp_valid(struct ocf_cache *cache,
if (!p2->config->flags.valid) {
if (p2_size) {
v2 = SHRT_MAX;
p1->config->flags.eviction = true;
p2->config->flags.eviction = true;
} else {
v2 = SHRT_MIN;
p2->config->flags.eviction = false;