linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate()
@ 2023-08-30  8:27 Rand Deeb
  2023-08-30 19:50 ` Larry Finger
  2023-08-31 13:45 ` Krzysztof Kozlowski
  0 siblings, 2 replies; 12+ messages in thread
From: Rand Deeb @ 2023-08-30  8:27 UTC (permalink / raw)
  To: Michael Buesch, linux-wireless, linux-kernel
  Cc: lvc-project, voskresenski.stanislav, Rand Deeb

In ssb_calc_clock_rate(), the value of m1 may be zero because it is
initialized using clkfactor_f6_resolv(). This function could return
zero, so there is a possibility of dividing by zero, we fixed it by
checking the values before dividing.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Rand Deeb <deeb.rand@confident.ru>
---
 drivers/ssb/main.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 0a26984acb2c..e0776a16d04d 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)
 		case SSB_CHIPCO_CLK_MC_BYPASS:
 			return clock;
 		case SSB_CHIPCO_CLK_MC_M1:
-			return (clock / m1);
+			if (m1 != 0)
+				return (clock / m1);
+			break;
 		case SSB_CHIPCO_CLK_MC_M1M2:
-			return (clock / (m1 * m2));
+			if ((m1 * m2) != 0)
+				return (clock / (m1 * m2));
+			break;
 		case SSB_CHIPCO_CLK_MC_M1M2M3:
-			return (clock / (m1 * m2 * m3));
+			if ((m1 * m2 * m3) != 0)
+				return (clock / (m1 * m2 * m3));
+			break;
 		case SSB_CHIPCO_CLK_MC_M1M3:
-			return (clock / (m1 * m3));
+			if ((m1 * m3) != 0)
+				return (clock / (m1 * m3));
+			break;
 		}
 		return 0;
 	case SSB_PLLTYPE_2:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-08-31 17:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30  8:27 [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate() Rand Deeb
2023-08-30 19:50 ` Larry Finger
2023-08-30 20:37   ` Michael Büsch
2023-08-31  7:07   ` Ранд Дееб
2023-08-31 13:46     ` Krzysztof Kozlowski
2023-08-31 15:35       ` Ранд Дееб
2023-08-31 16:05     ` Michael Büsch
2023-08-31 17:59       ` Larry Finger
2023-08-31 13:47   ` Krzysztof Kozlowski
2023-08-31 13:45 ` Krzysztof Kozlowski
2023-08-31 14:25   ` Ранд Дееб
2023-08-31 14:53     ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).