From 5a26067443621bf77e582be69b433540f7e657a8 Mon Sep 17 00:00:00 2001 From: Jingjing Wu Date: Sat, 10 Dec 2016 19:24:50 +0800 Subject: [PATCH] net/i40e/base: fix division by zero For some cases when reading from device are incorrect or image is incorrect, this part of code causes crash due to division by zero. Fixes: 8db9e2a1b232 ("i40e: base driver") Signed-off-by: Jingjing Wu --- drivers/net/i40e/base/i40e_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/i40e/base/i40e_common.c b/drivers/net/i40e/base/i40e_common.c index 14aaac6a36..fdf9d9b294 100644 --- a/drivers/net/i40e/base/i40e_common.c +++ b/drivers/net/i40e/base/i40e_common.c @@ -3967,8 +3967,10 @@ STATIC void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff, /* partition id is 1-based, and functions are evenly spread * across the ports as partitions */ - hw->partition_id = (hw->pf_id / hw->num_ports) + 1; - hw->num_partitions = num_functions / hw->num_ports; + if (hw->num_ports != 0) { + hw->partition_id = (hw->pf_id / hw->num_ports) + 1; + hw->num_partitions = num_functions / hw->num_ports; + } /* additional HW specific goodies that might * someday be HW version specific -- 2.20.1