Skip to content

Commit 1a9dc56

Browse files
d-tatianinkuba-moo
authored andcommitted
qed/qed_dev: guard against a possible division by zero
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 <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 22a825c commit 1a9dc56

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/net/ethernet/qlogic/qed/qed_dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,6 +5083,11 @@ static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
50835083

50845084
num_vports = p_hwfn->qm_info.num_vports;
50855085

5086+
if (num_vports < 2) {
5087+
DP_NOTICE(p_hwfn, "Unexpected num_vports: %d\n", num_vports);
5088+
return -EINVAL;
5089+
}
5090+
50865091
/* Accounting for the vports which are configured for WFQ explicitly */
50875092
for (i = 0; i < num_vports; i++) {
50885093
u32 tmp_speed;

0 commit comments

Comments
 (0)