Skip to contentSkip to conversation

m88ts2022: fix high symbol rate transponders missing on 32bit platform.

PATCH In review nibble.max 4 participants 5 messages Aug 16, 2014 Media (V4L/DVB)

lore
Share & tools
lore

nibble.max

author
#0 lore raw

PATCH 1/1 m88ts2022: fix high symbol rate transponders missing on 32bit platform.

The current m88ts2022 driver will miss the following high symbol rate transponders on Telstar 18 138.0. 12385 H 43200,
12690 H 43200,
12538 V 41250...
the code for f_3db_hz will overflow for the high symbol rate.
for example, symbol rate=41250 KS/s
symbol_rate * 135UL = 5568750000(1 4BEC 61B0), the value is larger than unsigned int on 32bit platform. that makes the wrong result.
Exchanging the div and mul position fixs it.

---
 drivers/media/tuners/m88ts2022.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/m88ts2022.c +1 -1
index 40c42de..65c8acc 100644
@@ -314,7 +314,7 @@ static int m88ts2022_set_params(struct dvb_frontend *fe)
 	div_min = gdiv28 * 78 / 100;
 	div_max = clamp_val(div_max, 0U, 63U);
 
-	f_3db_hz = c->symbol_rate * 135UL / 200UL;
+	f_3db_hz = (c->symbol_rate / 200UL) * 135UL;
 	f_3db_hz +=  2000000U + (frequency_offset_khz * 1000U);
 	f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U);
 
Signature · 1 line
1.9.1
#1 lore raw

Em Sat, 16 Aug 2014 14:12:32 +0800
"nibble.max" <[email protected]> escreveu:

Quoted 20 lines

The current m88ts2022 driver will miss the following high symbol rate transponders on Telstar 18 138.0. 12385 H 43200,
12690 H 43200,
12538 V 41250...
the code for f_3db_hz will overflow for the high symbol rate.
for example, symbol rate=41250 KS/s
symbol_rate * 135UL = 5568750000(1 4BEC 61B0), the value is larger than unsigned int on 32bit platform. that makes the wrong result.
Exchanging the div and mul position fixs it.

---
 drivers/media/tuners/m88ts2022.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/m88ts2022.c +0 -0
index 40c42de..65c8acc 100644

drivers/media/tuners/m88ts2022.c static int m88ts2022_set_params(struct dvb_frontend *fe) · line 317

Quoted 5 lines
drivers/media/tuners/m88ts2022.c +1 -1
@@ -314,7 +314,7 @@ static int m88ts2022_set_params(struct dvb_frontend *fe)
 	div_min = gdiv28 * 78 / 100;
 	div_max = clamp_val(div_max, 0U, 63U);
 
-	f_3db_hz = c->symbol_rate * 135UL / 200UL;
+	f_3db_hz = (c->symbol_rate / 200UL) * 135UL;

Hmm... wouldn't this make worse for low symbol rates?

IMHO, the better is to use a u64 instead, and do_div64().

drivers/media/tuners/m88ts2022.c static int m88ts2022_set_params(struct dvb_frontend *fe) · line 320

Quoted 3 lines
drivers/media/tuners/m88ts2022.c +0 -0
 	f_3db_hz +=  2000000U + (frequency_offset_khz * 1000U);
 	f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U);
 

Regards,

Signature · 2 lines
Cheers,
Mauro
#2 lore raw
Quoted 26 lines · Mauro Carvalho Chehab

Em Sat, 16 Aug 2014 14:12:32 +0800
"nibble.max" <[email protected]> escreveu:

Quoted 23 lines

The current m88ts2022 driver will miss the following high symbol rate transponders on Telstar 18 138.0. 12385 H 43200,
12690 H 43200,
12538 V 41250...
the code for f_3db_hz will overflow for the high symbol rate.
for example, symbol rate=41250 KS/s
symbol_rate * 135UL = 5568750000(1 4BEC 61B0), the value is larger than unsigned int on 32bit platform. that makes the wrong result.
Exchanging the div and mul position fixs it.

---
  drivers/media/tuners/m88ts2022.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/m88ts2022.c +0 -0
index 40c42de..65c8acc 100644
@@ -314,7 +314,7 @@ static int m88ts2022_set_params(struct dvb_frontend *fe)
  	div_min = gdiv28 * 78 / 100;
  	div_max = clamp_val(div_max, 0U, 63U);
 
Quoted 10 lines

drivers/media/tuners/m88ts2022.c static int m88ts2022_set_params(struct dvb_frontend *fe) · line 317

Quoted 2 lines
drivers/media/tuners/m88ts2022.c +1 -1
-	f_3db_hz = c->symbol_rate * 135UL / 200UL;
+	f_3db_hz = (c->symbol_rate / 200UL) * 135UL;

Hmm... wouldn't this make worse for low symbol rates?

IMHO, the better is to use a u64 instead, and do_div64().

Quoted 3 lines
drivers/media/tuners/m88ts2022.c +0 -0
  	f_3db_hz +=  2000000U + (frequency_offset_khz * 1000U);
  	f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U);
 

I will look that more carefully on end of next week, go through possible symbol rates and rounding errors.

Maybe it should be something like that (didn't test any way, may not even compile):
f_3db_hz = div_u64((u64) (c->symbol_rate * 135), 200);

Antti

Signature · 1 line
http://palosaari.fi/
#3 lore raw
Quoted 9 lines · Antti Palosaari

I will look that more carefully on end of next week, go through possible symbol rates and rounding errors.

Maybe it should be something like that (didn't test any way, may not even compile):
f_3db_hz = div_u64((u64) (c->symbol_rate * 135), 200);

In this case c->symbol_rate * 135 is still 32bits wide, but maybe signed because 135 is signed.
So there will be an overflow on 32bit platforms at symbol rates equal to 15907287.
So better cast symbol_rate to u64 before.

Matthias

author
#4 lore raw

Re: Re: [PATCH] m88ts2022: fix high symbol rate transponders missing on32bit platform.

In reply to nibble.max
Quoted 26 lines

Em Sat, 16 Aug 2014 14:12:32 +0800
"nibble.max" <[email protected]> escreveu:

Quoted 23 lines

The current m88ts2022 driver will miss the following high symbol rate transponders on Telstar 18 138.0. 12385 H 43200,
12690 H 43200,
12538 V 41250...
the code for f_3db_hz will overflow for the high symbol rate.
for example, symbol rate=41250 KS/s
symbol_rate * 135UL = 5568750000(1 4BEC 61B0), the value is larger than unsigned int on 32bit platform. that makes the wrong result.
Exchanging the div and mul position fixs it.

---
 drivers/media/tuners/m88ts2022.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/m88ts2022.c +0 -0
index 40c42de..65c8acc 100644
@@ -314,7 +314,7 @@ static int m88ts2022_set_params(struct dvb_frontend *fe)
 	div_min = gdiv28 * 78 / 100;
 	div_max = clamp_val(div_max, 0U, 63U);
 
Quoted 5 lines

drivers/media/tuners/m88ts2022.c static int m88ts2022_set_params(struct dvb_frontend *fe) · line 317

Quoted 2 lines
drivers/media/tuners/m88ts2022.c +1 -1
-	f_3db_hz = c->symbol_rate * 135UL / 200UL;
+	f_3db_hz = (c->symbol_rate / 200UL) * 135UL;

Hmm... wouldn't this make worse for low symbol rates?

The unit of symbol rate for Satellite is KS/s(1000S/s). So it is safe to divide 200 at the first.

Quoted 11 lines

IMHO, the better is to use a u64 instead, and do_div64().

drivers/media/tuners/m88ts2022.c static int m88ts2022_set_params(struct dvb_frontend *fe) · line 320

Quoted 3 lines
drivers/media/tuners/m88ts2022.c +0 -0
 	f_3db_hz +=  2000000U + (frequency_offset_khz * 1000U);
 	f_3db_hz = clamp(f_3db_hz, 7000000U, 40000000U);
 

Regards,

Signature · 2 lines
Cheers,
Mauro

BEGIN:VCARD
VERSION:2.1
N:nibble.max;
FN:nibble.max
EMAIL;PREF;INTERNET:[email protected]
REV:20140816T213101Z
END:VCARD