From 84b7ca8d81c370556e0c5f519b347d433fb68162 Mon Sep 17 00:00:00 2001 From: Matthew Duggan Date: Wed, 18 May 2022 17:05:54 +0900 Subject: [PATCH] storaged: Avoid divide-by-zero in performance measurement The code previously assumed that write() took a non-zero number of clock ticks. This is mostly true, but can't be guaranteed. Add a check to avoid crashing if it's 0. Bug: 233008287 Test: Compile Change-Id: Idec0052f534dc4abb81a414ca76f6c11f4a4dded (cherry picked from commit 5a02a9bab9db55ac02ab3eafd28e325233583a31) Merged-In: Idec0052f534dc4abb81a414ca76f6c11f4a4dded --- storaged/storaged.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp index 8cc8b596e..cefef6e06 100644 --- a/storaged/storaged.cpp +++ b/storaged/storaged.cpp @@ -333,7 +333,7 @@ void storaged_t::flush_proto_data(userid_t user_id, first_write = false; } - if (benchmark_size) { + if (benchmark_size && benchmark_time_ns) { int perf = benchmark_size * 1000000LLU / benchmark_time_ns; storage_info->update_perf_history(perf, system_clock::now()); }