[dpdk-dev,v2] net/i40e: fix division by 0 error

Message ID 1498215467-19681-1-git-send-email-wang.yong19@zte.com.cn (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Yong Wang June 23, 2017, 10:57 a.m. UTC
  In function i40e_vsi_config_tc_queue_mapping(), if 'enabled_tcmap' is
0, 'total_tc' might be 0. Then 'total_tc' might be used in a division
by 0 in "qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc)". Fix
it by changing 'total_tc' from 0 to 1 just as func
i40e_vsi_update_queue_mapping() does.

Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>
---
 drivers/net/i40e/i40e_ethdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Jingjing Wu June 29, 2017, 5:18 a.m. UTC | #1
> -----Original Message-----
> From: Yong Wang [mailto:wang.yong19@zte.com.cn]
> Sent: Friday, June 23, 2017 6:58 PM
> To: Wu, Jingjing <jingjing.wu@intel.com>
> Cc: dev@dpdk.org; Yong Wang <wang.yong19@zte.com.cn>
> Subject: [PATCH v2] net/i40e: fix division by 0 error
> 
> In function i40e_vsi_config_tc_queue_mapping(), if 'enabled_tcmap' is 0,
> 'total_tc' might be 0. Then 'total_tc' might be used in a division by 0 in
> "qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc)". Fix it by changing
> 'total_tc' from 0 to 1 just as func
> i40e_vsi_update_queue_mapping() does.
> 
> Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>


Acked-by: Jingjing Wu <jingjing.wu@intel.com>
  
Ferruh Yigit June 29, 2017, 11:14 a.m. UTC | #2
On 6/29/2017 6:18 AM, Wu, Jingjing wrote:
> 
> 
>> -----Original Message-----
>> From: Yong Wang [mailto:wang.yong19@zte.com.cn]
>> Sent: Friday, June 23, 2017 6:58 PM
>> To: Wu, Jingjing <jingjing.wu@intel.com>
>> Cc: dev@dpdk.org; Yong Wang <wang.yong19@zte.com.cn>
>> Subject: [PATCH v2] net/i40e: fix division by 0 error
>>
>> In function i40e_vsi_config_tc_queue_mapping(), if 'enabled_tcmap' is 0,
>> 'total_tc' might be 0. Then 'total_tc' might be used in a division by 0 in
>> "qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc)". Fix it by changing
>> 'total_tc' from 0 to 1 just as func
>> i40e_vsi_update_queue_mapping() does.
>>
>> Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>
> 
> 
> Acked-by: Jingjing Wu <jingjing.wu@intel.com>
> 

Fixes: 4861cde46116 ("i40e: new poll mode driver")

Applied to dpdk-next-net/master, thanks.


(Adding braces to for loop not required and not related the patch,
removed from patch)
  

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 4ee1113..0f54d09 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -4281,9 +4281,12 @@  enum i40e_status_code
 	if (ret != I40E_SUCCESS)
 		return ret;
 
-	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
+	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
 		if (enabled_tcmap & (1 << i))
 			total_tc++;
+	}
+	if (total_tc == 0)
+		total_tc = 1;
 	vsi->enabled_tc = enabled_tcmap;
 
 	/* Number of queues per enabled TC */