From: Peng Yixin Date: Fri, 27 Jul 2018 02:18:54 +0000 (+0800) Subject: codec_mm: fix some coverity error. X-Git-Tag: khadas-vims-v0.9.6-release~1549 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a070e94447b1afb88d766659e59f35870ee500b0;p=platform%2Fkernel%2Flinux-amlogic.git codec_mm: fix some coverity error. PD#170543: codec_mm: fix some coverity error. fix some coverity error Change-Id: Idf234f08bc6d7522fdeb04c14956d046c94012c4 Signed-off-by: Peng Yixin --- diff --git a/drivers/amlogic/media/common/codec_mm/codec_mm.c b/drivers/amlogic/media/common/codec_mm/codec_mm.c index da7591c..4cb1853 100644 --- a/drivers/amlogic/media/common/codec_mm/codec_mm.c +++ b/drivers/amlogic/media/common/codec_mm/codec_mm.c @@ -1935,7 +1935,7 @@ int codec_mm_trigger_help_fun(const char *trigger, int id, char *sbuf, int size) void *buf, *getbuf = NULL; if (size < PAGE_SIZE) { - void *getbuf = (void *)__get_free_page(GFP_KERNEL); + getbuf = (void *)__get_free_page(GFP_KERNEL); if (!getbuf) return -ENOMEM; @@ -1958,7 +1958,7 @@ int codec_mm_trigger_help_fun(const char *trigger, int id, char *sbuf, int size) ret = -1; } if (ret > 0 && getbuf != NULL) { - int ret = min_t(int, ret, size); + ret = min_t(int, ret, size); strncpy(sbuf, buf, ret); } diff --git a/drivers/amlogic/media/common/codec_mm/codec_mm_keeper.c b/drivers/amlogic/media/common/codec_mm/codec_mm_keeper.c index be409ce..9b98845 100644 --- a/drivers/amlogic/media/common/codec_mm/codec_mm_keeper.c +++ b/drivers/amlogic/media/common/codec_mm/codec_mm_keeper.c @@ -120,6 +120,11 @@ int codec_mm_keeper_mask_keep_mem(void *mem_handle, int type) if (!have_samed) keep_id = -1; } + if (codec_mm_get_keep_debug_mode() & 1) { + /*keeped info */ + pr_err("codec_mm_keeper_mask_keep_mem %p id=%d\n", + mem_handle, keep_id); + } if (keep_id < 0 || have_samed) { if (type == MEM_TYPE_CODEC_MM_SCATTER) ret = codec_mm_scatter_dec_keeper_user(mem_handle, 0); @@ -129,11 +134,7 @@ int codec_mm_keeper_mask_keep_mem(void *mem_handle, int type) pr_err("keep mem failed because keep buffer fulled!!!\n"); } spin_unlock_irqrestore(&mgr->lock, flags); - if (codec_mm_get_keep_debug_mode() & 1) { - /*keeped info */ - pr_err("codec_mm_keeper_mask_keep_mem %p id=%d\n", - mem_handle, keep_id); - } + return keep_id; } EXPORT_SYMBOL(codec_mm_keeper_mask_keep_mem); diff --git a/drivers/amlogic/media/common/codec_mm/codec_mm_scatter.c b/drivers/amlogic/media/common/codec_mm/codec_mm_scatter.c index b5c2d22..439c1d4 100644 --- a/drivers/amlogic/media/common/codec_mm/codec_mm_scatter.c +++ b/drivers/amlogic/media/common/codec_mm/codec_mm_scatter.c @@ -431,7 +431,7 @@ static int codec_mm_set_slot_in_hash( page_sid_type sid = SLOT_TO_SID(slot); - if (sid < 0 || sid > MAX_SID) { + if (sid > MAX_SID) { ERR_LOG("ERROR sid %d", sid); return -1; } @@ -469,7 +469,7 @@ static struct codec_mm_slot *codec_mm_find_slot_in_hash( { struct codec_mm_slot *fslot, *slot; - if (!VALID_SID(sid)) + if (!VALID_SID(sid) || SID_OF_ONEPAGE(sid)) return NULL; codec_mm_list_lock(smgt); fslot = smgt->slot_list_map[sid]; @@ -756,13 +756,14 @@ static int codec_mm_slot_alloc_pages( int need = num; int can_alloced; phy_addr_type page; - int tryn = slot->page_num; + int tryn; int i; if (!slot || !slot->pagemap) return -1; if (slot->alloced_page_num >= slot->page_num) return -2; + tryn = slot->page_num; can_alloced = slot->page_num - slot->alloced_page_num; need = need > can_alloced ? can_alloced : need; i = slot->next_bit; diff --git a/drivers/amlogic/media/common/codec_mm/configs/configs.c b/drivers/amlogic/media/common/codec_mm/configs/configs.c index 16b7d91..87f6299 100644 --- a/drivers/amlogic/media/common/codec_mm/configs/configs.c +++ b/drivers/amlogic/media/common/codec_mm/configs/configs.c @@ -477,6 +477,7 @@ static int configs_config2str(struct mconfig *config, case CONFIG_TYPE_BOOL: ret = snprintf(buf, size, "%s", config->pboolval ? "true" : "false"); + break; case CONFIG_TYPE_I32: ret = snprintf(buf, size, "%d", config->ival); break; @@ -707,9 +708,10 @@ static int configs_list_nodes_in(struct mconfig_node *node, struct list_head *node_list, *next; if (mode & LIST_MODE_PATH_PREFIX) { - if (node->depth > 0)/*not root.*/ + if (node->depth > 0) {/*not root.*/ strncat(cprefix, node->name, - MAX_PREFIX_NAME + MAX_ITEM_NAME); + MAX_PREFIX_NAME + MAX_ITEM_NAME - 1); + } } list_for_each_safe(node_list, next, &node->son_node_list) { snode = list_entry(node_list, @@ -871,8 +873,10 @@ static int configs_setget_config_value(struct mconfig *config, s = min_t(int, size - 1, config->size - 1); if (s > 0) strncpy(dst, src, s); - else + else { ret = -3; + break; + } ret = s; break; case CONFIG_TYPE_U32: diff --git a/drivers/amlogic/media/common/codec_mm/configs/configs_module.c b/drivers/amlogic/media/common/codec_mm/configs/configs_module.c index 0087625..e9664e9 100644 --- a/drivers/amlogic/media/common/codec_mm/configs/configs_module.c +++ b/drivers/amlogic/media/common/codec_mm/configs/configs_module.c @@ -340,6 +340,7 @@ static long configs_ioctl(struct file *file, unsigned int cmd, ulong arg) priv->access_get_cnt++; r = copy_from_user(&io.cmd_path, user_io->cmd_path, sizeof(io.cmd_path)); + io.cmd_path[sizeof(io.cmd_path) - 1] = '\0'; if (r) { r = -EIO; break;