[PATCH] rt-tests: hwlatdetect: Add check that width is not zero

John Kacur <[email protected]>
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
Check that width is not zero before division when calculating the MTBF

Signed-off-by: John Kacur <[email protected]>
---
 src/hwlatdetect/hwlatdetect.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index abfbb954fe75..42b9f301718a 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -564,8 +564,9 @@ if __name__ == '__main__':
     info(f"Samples exceeding threshold: {exceeding}")
 
     if exceeding > 1:
-        mtbf = ((float(detect.last) - float(detect.first)) * int(detect.get('window'))
-                / ((exceeding - 1) * int(detect.get('width'))))
+        width = int(detect.get('width'))
+        if width > 0:
+            mtbf = (((float(detect.last) - float(detect.first)) * int(detect.get('window'))) / ((exceeding - 1) * width))
         info(f"MTBF: {mtbf:.3f} seconds")
 
     if detect.have_msr:
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.