diff mbox series

[04/17] rt-tests: deadline_tests: Null check to prevent floating point exception

Message ID 20211111204207.10167-4-jkacur@redhat.com
State New
Headers show
Series [01/17] rt-tests:hwlatdetect: Remove useless object in class declaration | expand

Commit Message

John Kacur Nov. 11, 2021, 8:41 p.m. UTC
Fix a floating point exception that can occur if sd->nr_adjust is 0
by checking it before performing a division by zero.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/sched_deadline/deadline_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index 53abd4d2ca6b..b7e1e045b57c 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -2050,8 +2050,10 @@  int main(int argc, char **argv)
 		printf("missed deadlines  = %d\n", sd->missed_deadlines);
 		printf("missed periods    = %d\n", sd->missed_periods);
 		printf("Total adjustments = %lld us\n", sd->total_adjust);
-		printf("# adjustments = %lld avg: %lld us\n",
-		       sd->nr_adjust, sd->total_adjust / sd->nr_adjust);
+		if (sd->nr_adjust) {
+			printf("# adjustments = %lld avg: %lld us\n",
+			sd->nr_adjust, sd->total_adjust / sd->nr_adjust);
+		}
 		printf("deadline   : %lld us\n", sd->deadline_us);
 		printf("runtime    : %lld us\n", sd->runtime_us);
 		printf("nr_periods : %lld\n", sd->nr_periods);