diff mbox series

media: vidtv: fix time conversion error

Message ID 20200916190507.30476-1-alex.dewar90@gmail.com
State New
Headers show
Series media: vidtv: fix time conversion error | expand

Commit Message

Alex Dewar Sept. 16, 2020, 7:05 p.m. UTC
In vidtv_mux_check_mux_rate(), the function jiffies_to_usecs() is called
but its output is treated as if it were a value in milliseconds (indeed,
it is assigned to a variable called elapsed_time_msecs). Accordingly,
the calculation will be off by a factor of 1000. Fix this.

Addresses-Coverity: 1496996 ("Integer handling issues")
Fixes: f90cf6079bf6 ("media: vidtv: add a bridge driver")
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 drivers/media/test-drivers/vidtv/vidtv_mux.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/test-drivers/vidtv/vidtv_mux.c
index 5d1a275d504b..77b00a854a9c 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_mux.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c
@@ -349,12 +349,12 @@  static u32 vidtv_mux_check_mux_rate(struct vidtv_mux *m)
 	u64 nbytes_streamed; /* the number of bytes we actually wrote */
 	u32 num_null_pkts; /* number of null packets to bridge the gap */
 
-	u64 elapsed_time_msecs = jiffies_to_usecs(m->timing.current_jiffies -
+	u64 elapsed_time_usecs = jiffies_to_usecs(m->timing.current_jiffies -
 						  m->timing.past_jiffies);
 
-	elapsed_time_msecs = min(elapsed_time_msecs, (u64)VIDTV_MAX_SLEEP_USECS / 1000);
-	nbytes_expected = div64_u64(m->mux_rate_kbytes_sec * 1000, MSEC_PER_SEC);
-	nbytes_expected *= elapsed_time_msecs;
+	elapsed_time_usecs = min_t(u64, elapsed_time_usecs, VIDTV_MAX_SLEEP_USECS);
+	nbytes_expected = m->mux_rate_kbytes_sec; /* kb/sec is the same as bytes/msec */
+	nbytes_expected *= div64_u64(elapsed_time_usecs, 1000ULL);
 
 	nbytes_streamed = m->mux_buf_offset;