Skip to contentSkip to conversation

media: dvb-frontends: use div64_u64() instead of do_div()

PATCH In review Qing Wang 2 participants 2 messages Feb 9, 2022 – Feb 18, 2022 Media (V4L/DVB)

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 media: dvb-frontends: use div64_u64() instead of do_div()

From: Wang Qing <[email protected]>

do_div() does a 64-by-32 division.
When the divisor is u64, do_div() truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.

fix do_div.cocci warning:
do_div() does a 64-by-32 division, please consider using div64_u64 instead.

---
 drivers/media/dvb-frontends/tda10048.c     | 2 +-
 drivers/media/dvb-frontends/tda18271c2dd.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/tda10048.c +1 -1
index d1d206e..1ce2e67
@@ -344,7 +344,7 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz,
 	z = 7 * sample_freq_hz;
 	do_div(t, z);
 	t += 5;
-	do_div(t, 10);
+	div64_u64(t, 10);
 
 	tda10048_writereg(state, TDA10048_TIME_WREF_LSB, (u8)t);
 	tda10048_writereg(state, TDA10048_TIME_WREF_MID1, (u8)(t >> 8));
drivers/media/dvb-frontends/tda18271c2dd.c +2 -2
index a3483448..fd92878
@@ -328,7 +328,7 @@ static int CalcMainPLL(struct tda_state *state, u32 freq)
 
 	OscFreq = (u64) freq * (u64) Div;
 	OscFreq *= (u64) 16384;
-	do_div(OscFreq, (u64)16000000);
+	do_div(OscFreq, 16000000);
 	MainDiv = OscFreq;
 
 	state->m_Regs[MPD] = PostDiv & 0x77;
@@ -352,7 +352,7 @@ static int CalcCalPLL(struct tda_state *state, u32 freq)
 	OscFreq = (u64)freq * (u64)Div;
 	/* CalDiv = u32( OscFreq * 16384 / 16000000 ); */
 	OscFreq *= (u64)16384;
-	do_div(OscFreq, (u64)16000000);
+	do_div(OscFreq, 16000000);
 	CalDiv = OscFreq;
 
 	state->m_Regs[CPD] = PostDiv;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 20 lines · Qing Wang

From: Wang Qing <[email protected]>

do_div() does a 64-by-32 division.
When the divisor is u64, do_div() truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.

fix do_div.cocci warning:
do_div() does a 64-by-32 division, please consider using div64_u64 instead.

---
 drivers/media/dvb-frontends/tda10048.c     | 2 +-
 drivers/media/dvb-frontends/tda18271c2dd.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/media/dvb-frontends/tda10048.c +0 -0
index d1d206e..1ce2e67

drivers/media/dvb-frontends/tda10048.c static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz, · line 347

Quoted 5 lines
drivers/media/dvb-frontends/tda10048.c +1 -1
@@ -344,7 +344,7 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz,
 	z = 7 * sample_freq_hz;
 	do_div(t, z);
 	t += 5;
-	do_div(t, 10);
+	div64_u64(t, 10);

This makes no sense, I think you intended to convert the previous do_div(t, z).

Quoted 17 lines
drivers/media/dvb-frontends/tda10048.c +0 -0
 	tda10048_writereg(state, TDA10048_TIME_WREF_LSB, (u8)t);
 	tda10048_writereg(state, TDA10048_TIME_WREF_MID1, (u8)(t >> 8));
drivers/media/dvb-frontends/tda18271c2dd.c +1 -1
index a3483448..fd92878
@@ -328,7 +328,7 @@ static int CalcMainPLL(struct tda_state *state, u32 freq)
 
 	OscFreq = (u64) freq * (u64) Div;
 	OscFreq *= (u64) 16384;
-	do_div(OscFreq, (u64)16000000);
+	do_div(OscFreq, 16000000);
 	MainDiv = OscFreq;
 
 	state->m_Regs[MPD] = PostDiv & 0x77;

drivers/media/dvb-frontends/tda18271c2dd.c static int CalcCalPLL(struct tda_state *state, u32 freq) · line 358

Quoted 8 lines
drivers/media/dvb-frontends/tda18271c2dd.c +1 -1
@@ -352,7 +352,7 @@ static int CalcCalPLL(struct tda_state *state, u32 freq)
 	OscFreq = (u64)freq * (u64)Div;
 	/* CalDiv = u32( OscFreq * 16384 / 16000000 ); */
 	OscFreq *= (u64)16384;
-	do_div(OscFreq, (u64)16000000);
+	do_div(OscFreq, 16000000);
 	CalDiv = OscFreq;
 
 	state->m_Regs[CPD] = PostDiv;

The changes here do not match with the subject line of this patch. I think it is best to split this into two patches, one for each source.

Regards,

Hans