Skip to content

Commit

Permalink
qed/qed_dev: guard against a possible division by zero
Browse files Browse the repository at this point in the history
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 validating num_vports at
the beginning and returning an error otherwise.

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

Fixes: bcd197c ("qed: Add vport WFQ configuration APIs")
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230309201556.191392-1-d-tatianin@yandex-team.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Daniil Tatianin authored and Jakub Kicinski committed Mar 13, 2023
1 parent 22a825c commit 1a9dc56
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/net/ethernet/qlogic/qed/qed_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5083,6 +5083,11 @@ static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,

num_vports = p_hwfn->qm_info.num_vports;

if (num_vports < 2) {
DP_NOTICE(p_hwfn, "Unexpected num_vports: %d\n", num_vports);
return -EINVAL;
}

/* Accounting for the vports which are configured for WFQ explicitly */
for (i = 0; i < num_vports; i++) {
u32 tmp_speed;
Expand Down

0 comments on commit 1a9dc56

Please sign in to comment.