Skip to contentSkip to conversation

net/qede/base: fix division by zero

PATCH New Bulatov Mark 1 participant 1 message Nov 13 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/qede/base: fix division by zero

From: Mark Bulatov <[email protected]>

In the ecore_init_wfq_param() function, calculating left_rate_per_vp will result in a division by zero if num_vports and req_count are configured to have equal values.

Fix this by adding an extra check.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes ec94dbc573 ("qede: add base driver")
---
 drivers/net/qede/base/ecore_dev.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/qede/base/ecore_dev.c +7 -0
index e895dee405..2082971b0b 100644
@@ -6481,6 +6481,13 @@ static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
 		return ECORE_INVAL;
 	}
 
+	/* Validate non_requested_count is non-zero */
+	if (non_requested_count == 0) {
+		DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
+			   "The number of vports is equal to the number of requests\n");
+		return ECORE_INVAL;
+	}
+
 	/* Data left for non requested vports */
 	total_left_rate = min_pf_rate - total_req_min_rate;
 	left_rate_per_vp = total_left_rate / non_requested_count;
Signature · 1 line
2.39.5