From patchwork Thu Mar 7 13:19:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniil Dulov X-Patchwork-Id: 13585556 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-out.aladdin-rd.ru (mail-out.aladdin-rd.ru [91.199.251.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 997EB12C52D; Thu, 7 Mar 2024 13:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.199.251.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709817636; cv=none; b=MFneFFAtwAxX3ryjrUTBcjY3VyZJGk0XGwJHqC3rJUele1zr7+EMWG7gV3CQ6mkeUqjbQnojRzlYvb+kEHayZbeXWkTW9bfDYplhfZQmcxKMoOR6WabTZ7w6LiEnOu3aZ6/7IV5dpON1mEK4m+qwEGOdQomT9uTyZjPDkSkba8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709817636; c=relaxed/simple; bh=p0S6TKLtZr54QKpjwWO7mH2N9msbPcid8zVNvisldXE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=j/QyVidGnbu/NAODMMrdPMtv461xBJB2Kkre7LhEcJGNSK9xmSutcdPyBsP3m0aiWgIgWyyZm+fy4q0EdMmNBuHlPDMpZGqssKrTW31jSE8A24QuiBWnDjx2iEeAXukkFmHNXRC2q0rZVqr2cc8Uo46/RFCEDlolQE/49z8PN5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru; spf=pass smtp.mailfrom=aladdin.ru; arc=none smtp.client-ip=91.199.251.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aladdin.ru From: Daniil Dulov To: Doug Berger CC: Daniil Dulov , Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , , , Subject: [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow Date: Thu, 7 Mar 2024 16:19:47 +0300 Message-ID: <20240307131947.13133-1-d.dulov@aladdin.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EXCH-2016-01.aladdin.ru (192.168.1.101) To EXCH-2016-01.aladdin.ru (192.168.1.101) X-Patchwork-Delegate: kuba@kernel.org The expression priv->clk_freq * 2 can lead to overflow that will cause a division by zero. So, let's cast it to unsigned long to avoid it. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: b78ac6ecd1b6 ("net: phy: mdio-bcm-unimac: Allow configuring MDIO clock divider") Signed-off-by: Daniil Dulov Acked-by: Florian Fainelli --- drivers/net/mdio/mdio-bcm-unimac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c index 68f8ee0ec8ba..055102e6bb6d 100644 --- a/drivers/net/mdio/mdio-bcm-unimac.c +++ b/drivers/net/mdio/mdio-bcm-unimac.c @@ -192,7 +192,7 @@ static void unimac_mdio_clk_set(struct unimac_mdio_priv *priv) else rate = clk_get_rate(priv->clk); - div = (rate / (2 * priv->clk_freq)) - 1; + div = (rate / (2 * (unsigned long)priv->clk_freq)) - 1; if (div & ~MDIO_CLK_DIV_MASK) { pr_warn("Incorrect MDIO clock frequency, ignoring\n"); return;