mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Dewar <alex.dewar90@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Alex Dewar <alex.dewar90@gmail.com>,
	"Daniel W. S. Almeida" <dwlsalmeida@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: vidtv: fix time conversion error
Date: Wed, 16 Sep 2020 20:05:06 +0100	[thread overview]
Message-ID: <20200916190507.30476-1-alex.dewar90@gmail.com> (raw)

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 --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;
 
-- 
2.28.0


                 reply	other threads:[~2020-09-16 19:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200916190507.30476-1-alex.dewar90@gmail.com \
    --to=alex.dewar90@gmail.com \
    --cc=dwlsalmeida@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®