From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0E6C6A04B5; Mon, 2 Dec 2019 09:07:26 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 85B531C18F; Mon, 2 Dec 2019 08:59:27 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 99B1C1C0D9 for ; Mon, 2 Dec 2019 08:59:12 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Dec 2019 23:59:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,268,1571727600"; d="scan'208";a="207993718" Received: from dpdk_yexl_af_xdp.sh.intel.com ([10.67.119.186]) by fmsmga008.fm.intel.com with ESMTP; 01 Dec 2019 23:59:10 -0800 From: Xiaolong Ye To: Beilei Xing , Qi Zhang Cc: dev@dpdk.org, Xiaolong Ye , Sergey Nemov Date: Mon, 2 Dec 2019 15:49:25 +0800 Message-Id: <20191202074935.97629-60-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191202074935.97629-1-xiaolong.ye@intel.com> References: <20191202074935.97629-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 59/69] net/i40e/base: put the check for zero nested elements higher X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Checking for == 0 on some elements resulted in unreachable code discovered by static analyzer. Put this check higher in the code structure to make the analyzer happy. Signed-off-by: Sergey Nemov Reviewed-by: Aleksandr Loktionov Signed-off-by: Xiaolong Ye --- drivers/net/i40e/base/virtchnl.h | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/net/i40e/base/virtchnl.h b/drivers/net/i40e/base/virtchnl.h index 6384ded7d..46fdca1aa 100644 --- a/drivers/net/i40e/base/virtchnl.h +++ b/drivers/net/i40e/base/virtchnl.h @@ -1163,7 +1163,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_vsi_queue_config_info *vqc = (struct virtchnl_vsi_queue_config_info *)msg; - if (vqc->num_queue_pairs > + if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs > VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) { err_msg_format = true; break; @@ -1172,8 +1172,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, valid_len += (vqc->num_queue_pairs * sizeof(struct virtchnl_queue_pair_info)); - if (vqc->num_queue_pairs == 0) - err_msg_format = true; } break; case VIRTCHNL_OP_CONFIG_IRQ_MAP: @@ -1182,7 +1180,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_irq_map_info *vimi = (struct virtchnl_irq_map_info *)msg; - if (vimi->num_vectors > + if (vimi->num_vectors == 0 || vimi->num_vectors > VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) { err_msg_format = true; break; @@ -1190,9 +1188,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, valid_len += (vimi->num_vectors * sizeof(struct virtchnl_vector_map)); - - if (vimi->num_vectors == 0) - err_msg_format = true; } break; case VIRTCHNL_OP_ENABLE_QUEUES: @@ -1206,7 +1201,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_ether_addr_list *veal = (struct virtchnl_ether_addr_list *)msg; - if (veal->num_elements > + if (veal->num_elements == 0 || veal->num_elements > VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) { err_msg_format = true; break; @@ -1214,8 +1209,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, valid_len += veal->num_elements * sizeof(struct virtchnl_ether_addr); - if (veal->num_elements == 0) - err_msg_format = true; } break; case VIRTCHNL_OP_ADD_VLAN: @@ -1225,16 +1218,13 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_vlan_filter_list *vfl = (struct virtchnl_vlan_filter_list *)msg; - if (vfl->num_elements > + if (vfl->num_elements == 0 || vfl->num_elements > VIRTCHNL_OP_ADD_DEL_VLAN_MAX) { err_msg_format = true; break; } valid_len += vfl->num_elements * sizeof(u16); - - if (vfl->num_elements == 0) - err_msg_format = true; } break; case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: @@ -1262,16 +1252,12 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_iwarp_qvlist_info *qv = (struct virtchnl_iwarp_qvlist_info *)msg; - if (qv->num_vectors > + if (qv->num_vectors == 0 || qv->num_vectors > VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP_MAX) { err_msg_format = true; break; } - if (qv->num_vectors == 0) { - err_msg_format = true; - break; - } valid_len += ((qv->num_vectors - 1) * sizeof(struct virtchnl_iwarp_qv_info)); } @@ -1310,7 +1296,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, struct virtchnl_tc_info *vti = (struct virtchnl_tc_info *)msg; - if (vti->num_tc > + if (vti->num_tc == 0 || vti->num_tc > VIRTCHNL_OP_ENABLE_CHANNELS_MAX) { err_msg_format = true; break; @@ -1318,8 +1304,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, valid_len += (vti->num_tc - 1) * sizeof(struct virtchnl_channel_info); - if (vti->num_tc == 0) - err_msg_format = true; } break; case VIRTCHNL_OP_DISABLE_CHANNELS: -- 2.17.1