All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rand Deeb <deeb.rand@confident.ru>
To: stable@vger.kernel.org, gregkh@linuxfoundation.org
Cc: lvc-project@linuxtesting.org,
	voskresenski.stanislav@confident.ru,
	Rand Deeb <deeb.rand@confident.ru>
Subject: [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate()
Date: Tue, 29 Aug 2023 14:12:51 +0300	[thread overview]
Message-ID: <20230829111251.6190-1-deeb.rand@confident.ru> (raw)

In the line 910, the value of m1 may be zero, so there is a possibility
of dividing by zero, we fixed it by checking the values before dividing
(found with SVACE). In the same way, after checking and reading the
function, we found that lines 906, 908, 912 have the same situation, so
we fixed them as well.

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


             reply	other threads:[~2023-08-29 11:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 11:12 Rand Deeb [this message]
2023-08-29 13:26 ` [lvc-project] [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate() Alexey Khoroshilov
2023-08-29 17:35 ` Krzysztof Kozlowski
  -- strict thread matches above, loose matches on Subject: below --
2023-08-30  8:27 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

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=20230829111251.6190-1-deeb.rand@confident.ru \
    --to=deeb.rand@confident.ru \
    --cc=gregkh@linuxfoundation.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=stable@vger.kernel.org \
    --cc=voskresenski.stanislav@confident.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.