From patchwork Thu Mar 9 12:56:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniil Tatianin X-Patchwork-Id: 13167380 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8633AC64EC4 for ; Thu, 9 Mar 2023 13:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbjCINAh (ORCPT ); Thu, 9 Mar 2023 08:00:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjCINAR (ORCPT ); Thu, 9 Mar 2023 08:00:17 -0500 Received: from forwardcorp1b.mail.yandex.net (forwardcorp1b.mail.yandex.net [178.154.239.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 568B0F2C3C; Thu, 9 Mar 2023 04:59:13 -0800 (PST) Received: from mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:5398:0:640:443b:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id E04DE60E05; Thu, 9 Mar 2023 15:57:01 +0300 (MSK) Received: from d-tatianin-nix.HomeLAN (unknown [2a02:6b8:b081:b70e::1:20]) by mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id pucJk20OqmI0-vYHLLI0n; Thu, 09 Mar 2023 15:57:00 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1678366621; bh=EPwunAXouBa4A6BU9aAvadf8EHtbYlPqNUac44W5NzM=; h=Message-Id:Date:Cc:Subject:To:From; b=1c8VBTRNIxao501g3zD3Y7b3YUOutpAbKLVGqBe3JDLgsMwiYPhaFvEk8EQuLUkAc 1JYZxdhqn6XVPaM2BP5OkE2JQ9BYUNA0RKavTSXGHcDM/l79eFMhqQi5KqvPx+ErBD RwkiDCaAapuI3x5b+NID5XxNekKZEdjXzug3kGqQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-44.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Daniil Tatianin To: Ariel Elior Cc: Daniil Tatianin , Manish Chopra , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yuval Mintz , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] qed/qed_dev: guard against a possible division by zero Date: Thu, 9 Mar 2023 15:56:36 +0300 Message-Id: <20230309125636.176337-1-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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: bcd197c81f63 ("qed: Add vport WFQ configuration APIs") Signed-off-by: Daniil Tatianin Reviewed-by: Simon Horman --- drivers/net/ethernet/qlogic/qed/qed_dev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c index d61cd32ec3b6..9aaaf5ad3eb0 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_dev.c +++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c @@ -5083,6 +5083,13 @@ 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;