linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] media: vidtv: cleanup the logic which estimates buffer size
@ 2020-09-17  9:51 Mauro Carvalho Chehab
  2020-09-17  9:51 ` [PATCH 2/2] media: vidtv: remove an impossible condition Mauro Carvalho Chehab
  0 siblings, 1 reply; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-17  9:51 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

There's no need to use u64 over there. In a matter of fact,
the div is not even needed, as it is multiplying by 1000 and
dividing by 1000.

So, simplify the logic.

While here, constrain the buffer size to a certain range
(between the current value and 10 times it)

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 .../media/test-drivers/vidtv/vidtv_bridge.c   | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
index fe4e496acc34..74b054947bbe 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
@@ -106,26 +106,28 @@ static unsigned int mux_buf_sz_pkts;
 module_param(mux_buf_sz_pkts, uint, 0);
 MODULE_PARM_DESC(mux_buf_sz_pkts, "Size for the internal mux buffer in multiples of 188 bytes");
 
+#define MUX_BUF_MIN_SZ 90164
+#define MUX_BUF_MAX_SZ (MUX_BUF_MIN_SZ * 10)
+
 static u32 vidtv_bridge_mux_buf_sz_for_mux_rate(void)
 {
-	u64 max_elapsed_time_msecs =  VIDTV_MAX_SLEEP_USECS / 1000;
+	u32 max_elapsed_time_msecs =  VIDTV_MAX_SLEEP_USECS / USEC_PER_MSEC;
 	u32 nbytes_expected;
 	u32 mux_buf_sz = mux_buf_sz_pkts * TS_PACKET_LEN;
-	u32 slack;
 
-	nbytes_expected = div64_u64(mux_rate_kbytes_sec * 1000, MSEC_PER_SEC);
+	nbytes_expected = mux_rate_kbytes_sec;
 	nbytes_expected *= max_elapsed_time_msecs;
 
 	mux_buf_sz = roundup(nbytes_expected, TS_PACKET_LEN);
-	slack = mux_buf_sz / 10;
+	mux_buf_sz += mux_buf_sz / 10;
 
-	//if (mux_buf_sz < MUX_BUF_MIN_SZ)
-	//	mux_buf_sz = MUX_BUF_MIN_SZ;
+	if (mux_buf_sz < MUX_BUF_MIN_SZ)
+		mux_buf_sz = MUX_BUF_MIN_SZ;
 
-	//if (mux_buf_sz > MUX_BUF_MAX_SZ)
-	//	mux_buf_sz = MUX_BUF_MAX_SZ;
+	if (mux_buf_sz > MUX_BUF_MAX_SZ)
+		mux_buf_sz = MUX_BUF_MAX_SZ;
 
-	return mux_buf_sz + slack;
+	return mux_buf_sz;
 }
 
 static bool vidtv_bridge_check_demod_lock(struct vidtv_dvb *dvb, u32 n)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] media: vidtv: remove an impossible condition
  2020-09-17  9:51 [PATCH 1/2] media: vidtv: cleanup the logic which estimates buffer size Mauro Carvalho Chehab
@ 2020-09-17  9:51 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2020-09-17  9:51 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Daniel W. S. Almeida,
	Mauro Carvalho Chehab, linux-kernel, linux-media

As warned by smatch:

	drivers/media/test-drivers/vidtv/vidtv_psi.c:93 vidtv_psi_update_version_num() warn: impossible condition '(h->version > 32) => (0-31 > 32)'

h_version is declared as:

		u8  version:5;

Meaning that its value ranges from 0 to 31. Incrementing 31 on such
data will overflow to zero, as expected.

So, just drop the uneeded overflow check.

While here, use "foo++" instead of "++foo", as this is a much
more common pattern.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/test-drivers/vidtv/vidtv_psi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_psi.c b/drivers/media/test-drivers/vidtv/vidtv_psi.c
index b8b638244b1d..8cdf645b4fdd 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_psi.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_psi.c
@@ -89,9 +89,7 @@ static inline u32 dvb_crc32(u32 crc, u8 *data, u32 len)
 
 static void vidtv_psi_update_version_num(struct vidtv_psi_table_header *h)
 {
-	++h->version;
-	if (h->version > MAX_VERSION_NUM)
-		h->version = 0;
+	h->version++;
 }
 
 static inline u16 vidtv_psi_sdt_serv_get_desc_loop_len(struct vidtv_psi_table_sdt_service *s)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-17  9:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17  9:51 [PATCH 1/2] media: vidtv: cleanup the logic which estimates buffer size Mauro Carvalho Chehab
2020-09-17  9:51 ` [PATCH 2/2] media: vidtv: remove an impossible condition Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).