From 5f81173844bd96add1897521a28e446326a9a7f0 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 17 Sep 2019 09:12:49 -0400 Subject: [PATCH 1/5] Leave space for terminating \0 in cache name initialization. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/layer_cache_management.c | 2 +- modules/cas_cache/layer_upgrade.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 770d0d2..8495617 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1060,7 +1060,7 @@ int cache_mngt_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg, memset(device_cfg, 0, sizeof(*device_cfg)); memset(atomic_params, 0, sizeof(*atomic_params)); - strncpy(cfg->name, cache_name, OCF_CACHE_NAME_SIZE); + strncpy(cfg->name, cache_name, OCF_CACHE_NAME_SIZE - 1); cfg->cache_mode = cmd->caching_mode; cfg->cache_line_size = cmd->line_size; cfg->eviction_policy = cmd->eviction_policy; diff --git a/modules/cas_cache/layer_upgrade.c b/modules/cas_cache/layer_upgrade.c index 93980aa..f612f0a 100644 --- a/modules/cas_cache/layer_upgrade.c +++ b/modules/cas_cache/layer_upgrade.c @@ -861,7 +861,7 @@ static int _cas_upgrade_restore_conf_main(struct cas_properties *cache_props, if (cache_mode >= ocf_cache_mode_max) cache_mode = ocf_cache_mode_default; - strncpy(cfg.name, cache_name, OCF_CACHE_NAME_SIZE); + strncpy(cfg.name, cache_name, OCF_CACHE_NAME_SIZE - 1); cfg.cache_mode = cache_mode; /* cfg.eviction_policy = TODO */ cfg.cache_line_size = cache_line_size; From 8e64392298e616ab7dff3ae4a23a3ccd6cd37710 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 17 Sep 2019 10:25:25 -0400 Subject: [PATCH 2/5] Validate log level provided to logger. Check if provided log level isn't greater than number of available log levels Prevoius check was comparing log level to size of array with avaiable log levels (in bytes). Signed-off-by: Michal Mielewczyk --- modules/cas_cache/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cas_cache/context.c b/modules/cas_cache/context.c index 50cbf1b..d653abf 100644 --- a/modules/cas_cache/context.c +++ b/modules/cas_cache/context.c @@ -314,7 +314,7 @@ static int _cas_ctx_logger_print(ocf_logger_t logger, ocf_logger_lvl_t lvl, [log_debug] = KERN_DEBUG, }; char *format; - if (((unsigned)lvl) >= sizeof(level)) + if (((unsigned)lvl) >= sizeof(level)/sizeof(level[0])) return -EINVAL; format = kasprintf(GFP_ATOMIC, "%s%s", level[lvl], fmt); From a48db4aadf84ab160cc356d7bea16327b3d1f51e Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 17 Sep 2019 11:16:02 -0400 Subject: [PATCH 3/5] Fix printing cache properties in upgrade. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/utils/utils_properties.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/utils/utils_properties.c b/modules/cas_cache/utils/utils_properties.c index 111868b..4c32236 100644 --- a/modules/cas_cache/utils/utils_properties.c +++ b/modules/cas_cache/utils/utils_properties.c @@ -365,7 +365,6 @@ error_after_buffer_allocation: void cas_properties_print(struct cas_properties *props) { - int result = 0; struct list_head *curr; struct _cas_property *entry; char *abc; @@ -387,8 +386,9 @@ void cas_properties_print(struct cas_properties *props) case cas_property_uint: printk(", uint, "); printk("Value: %llu ", entry->value_uint); + break; default: - result = -EINVAL; + printk("Invalid type!"); break; } printk("\n"); From 488c76a8fc6ac68d72bbbaf97b71c9c2edd0627a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 18 Sep 2019 02:14:59 -0400 Subject: [PATCH 4/5] Explanation comment for complex casadm logic. Different static analysis tools detects division by 0. To avoid reanalyzing this piece of code, explanation comment was added. Signed-off-by: Michal Mielewczyk --- casadm/statistics_view_text.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/casadm/statistics_view_text.c b/casadm/statistics_view_text.c index 07f1fc5..daf6130 100644 --- a/casadm/statistics_view_text.c +++ b/casadm/statistics_view_text.c @@ -882,6 +882,10 @@ static int adjust_column_widths(struct view_t *this, for (i = 0 ; i != w ; ++i) { int this_width = vector_get(&prv->col_w, i); + /* + * This condition is exactly the same as in above loop, where + * above_avg_cols is incremented. So there is no risk of division by 0. + */ if (this_width > avg_width) { int reduce_by = excess_width / above_avg_cols; vector_set(&prv->col_w, i, this_width - reduce_by); From 7d4972a40ec8e72f6788e40db906c3f904625876 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 18 Sep 2019 02:42:46 -0400 Subject: [PATCH 5/5] Remove irrelevant comment about changing cache modes. Signed-off-by: Michal Mielewczyk --- modules/include/cas_ioctl_codes.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index 3de6cbd..fa3332e 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -96,17 +96,8 @@ struct kcas_stop_cache { struct kcas_set_cache_state { uint16_t cache_id; /**< id of cache for which state should be set */ - /** - * caching mode for new cache instance - * valid choices are: - * * WRITE_THROUGH - * * WRITE_BACK - * * WRITE_AROUND - * * PASS_THROUGH - */ ocf_cache_mode_t caching_mode; - uint8_t flush_data; /**< should data be flushed? */ int ext_err_code;