public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: Ariel Elior <aelior@marvell.com>,
	Manish Chopra <manishc@marvell.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Yuval Mintz <Yuval.Mintz@qlogic.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v0] qed/qed_dev: guard against a possible division by zero
Date: Thu, 9 Feb 2023 12:13:26 +0100	[thread overview]
Message-ID: <Y+TVVuLgF+V7iTO1@corigine.com> (raw)
In-Reply-To: <20230209103813.2500486-1-d-tatianin@yandex-team.ru>

On Thu, Feb 09, 2023 at 01:38:13PM +0300, Daniil Tatianin wrote:
> 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);

I don't know if num_vports can be 1.
But if it is then I agree that the above will be a divide by zero.

I do, however, wonder if it would be better to either:

* Treat this case as invalid and return with -EINVAL if num_vports is 1; or

* Skip both the calculation immediately above and the code
  in the if condition below, which is the only place where
  the calculated value is used, if num_vports is 1.
  I don't think the if clause makes much sense if num_vports is one.

>  	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
> 

  reply	other threads:[~2023-02-09 11:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y+TVVuLgF+V7iTO1@corigine.com \
    --to=simon.horman@corigine.com \
    --cc=Yuval.Mintz@qlogic.com \
    --cc=aelior@marvell.com \
    --cc=d-tatianin@yandex-team.ru \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manishc@marvell.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox