public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0] qed/qed_dev: guard against a possible division by zero
@ 2023-02-09 10:38 Daniil Tatianin
  2023-02-09 11:13 ` Simon Horman
  0 siblings, 1 reply; 8+ messages in thread
From: Daniil Tatianin @ 2023-02-09 10:38 UTC (permalink / raw)
  To: Ariel Elior
  Cc: Daniil Tatianin, Manish Chopra, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Yuval Mintz, netdev, linux-kernel

Previously we would divide total_left_rate by zero if num_vports
happened to be 1 because non_requested_count is calculated as
num_vports - req_count. Guard against this by explicitly checking for
zero when doing the division.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.

Fixes: bcd197c81f63 ("qed: Add vport WFQ configuration APIs")
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
 drivers/net/ethernet/qlogic/qed/qed_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c
index d61cd32ec3b6..90927f68c459 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dev.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c
@@ -5123,7 +5123,7 @@ static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
 
 	total_left_rate	= min_pf_rate - total_req_min_rate;
 
-	left_rate_per_vp = total_left_rate / non_requested_count;
+	left_rate_per_vp = total_left_rate / (non_requested_count ?: 1);
 	if (left_rate_per_vp <  min_pf_rate / QED_WFQ_UNIT) {
 		DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
 			   "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-03-07 19:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-09 10:38 [PATCH v0] qed/qed_dev: guard against a possible division by zero Daniil Tatianin
2023-02-09 11:13 ` Simon Horman
2023-02-14  7:23   ` Daniil Tatianin
2023-02-15 21:20     ` [EXT] " Manish Chopra
2023-02-16  6:42       ` Daniil Tatianin
2023-03-03 12:18         ` Daniil Tatianin
2023-03-07 17:50           ` Manish Chopra
2023-03-07 19:28             ` Daniil Tatianin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox