From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96D1DEED615 for ; Thu, 12 Sep 2024 15:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=l74tabVM84DRE/8Wy+tXY+3qcDErNA6rPvHSYtT/1rA=; b=19u8AzG3FiHjsngHd2nRwVxfMP GEFVBz6wQ1kjtFeW31+3UZvYXyVSzzgVrvhkj7rbrQoy7ISYugwYW0+MZhi1BorGDEse7bOjI3oPg QaGeWb0xMqdDHgiIagp4MZqkxuM/6p9qIKCwfad94TdoYC/D/CZ9tujHfpCsMLeMiymSotTzBCCtq zq6lx+YqlXKz3FuxO3PLTdyPMn0mNbrQjEODuUbaaVU+gjMHzU9L15/vUc+ZJWQo5PzSnvUIG9fj6 9J6Yl1SxoYBTmoeB6YLskJeQPLVDCuMledNxBtGwmJ7q0Qa4VGkCc0VbQInz45UD1JkVojFjqij2I nv9y/PWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soluA-0000000Daad-2EN2; Thu, 12 Sep 2024 15:38:46 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solt3-0000000DaDp-0gZR for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:37:39 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 8D06CA456B0; Thu, 12 Sep 2024 15:37:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB574C4CEC3; Thu, 12 Sep 2024 15:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726155455; bh=N/+WNeF+RDLG1ngsWQ16huQXqFJqMaiTBQhwf09Ovlw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bbS1dzrJOj5tds7MBnce/FTebHyPXH1Re3Wsx5wcDhTHcThsHGJGnISRw4fyJwaNi 1xSnsYtZ11ng94GVqnlMpyfivdkC3dOl+sIekye8vD7H14dk/RTmMajsIBR140jGKn C9Mols8RTbIXlGeipygGOAb7oQy3DSpLwGGBeeN4XhNw5mtvEB2AksUHNLWOdBQy0u oJv8k+/EPQrshEpB7GTL0Fs5+nC9H+4A2beRcsajAL+5j6Crr7wbWYHoWaEEAD16eK qIHNYWrefsyKEQFZNgxWQMaIv2qEnUkeJKsXg23ratJRIjvDXnsoW/VXj9B8DlQ0kC gvais+ESwUuZA== Date: Thu, 12 Sep 2024 16:37:30 +0100 From: Simon Horman To: KhaiWenTan Cc: Alexandre Torgue , Jose Abreu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Xiaolei Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Choong Yong Liang , Tan Khai Wen Subject: Re: [PATCH net 1/1] net: stmmac: Fix zero-division error when disabling tc cbs Message-ID: <20240912153730.GN572255@kernel.org> References: <20240912015541.363600-1-khai.wen.tan@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240912015541.363600-1-khai.wen.tan@linux.intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_083737_367299_E090383D X-CRM114-Status: GOOD ( 25.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 12, 2024 at 09:55:41AM +0800, KhaiWenTan wrote: > The commit b8c43360f6e4 ("net: stmmac: No need to calculate speed divider > when offload is disabled") allows the "port_transmit_rate_kbps" to be > set to a value of 0, which is then passed to the "div_s64" function when > tc-cbs is disabled. This leads to a zero-division error. > > When tc-cbs is disabled, the idleslope, sendslope, and credit values the > credit values are not required to be configured. Therefore, adding a return > statement after setting the txQ mode to DCB when tc-cbs is disabled would > prevent a zero-division error. > > Fixes: b8c43360f6e4 ("net: stmmac: No need to calculate speed divider when offload is disabled") > Cc: > Co-developed-by: Choong Yong Liang > Signed-off-by: Choong Yong Liang > Signed-off-by: KhaiWenTan > --- > drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > index 996f2bcd07a2..2c3fd9c66d14 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > @@ -392,10 +392,10 @@ static int tc_setup_cbs(struct stmmac_priv *priv, > } else if (!qopt->enable) { > ret = stmmac_dma_qmode(priv, priv->ioaddr, queue, > MTL_QUEUE_DCB); > - if (ret) > - return ret; > + if (!ret) > + priv->plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB; > > - priv->plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB; > + return ret; > } Thanks, I agree with your analysis. But I think it would be more idomatic to write it such that the main thread of execution is the non-error path (in any case, it makes it easier for me to understand the intent of the code. What I am suggesting is this (extra context provided for clarity): diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index 996f2bcd07a2..308ef4241768 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -392,14 +392,15 @@ static int tc_setup_cbs(struct stmmac_priv *priv, } else if (!qopt->enable) { ret = stmmac_dma_qmode(priv, priv->ioaddr, queue, MTL_QUEUE_DCB); if (ret) return ret; priv->plat->tx_queues_cfg[queue].mode_to_use = MTL_QUEUE_DCB; + return 0; } /* Final adjustments for HW */ value = div_s64(qopt->idleslope * 1024ll * ptr, port_transmit_rate_kbps); priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0); value = div_s64(-qopt->sendslope * 1024ll * ptr, port_transmit_rate_kbps);