[PATCH] media: dib7000p: fall back to 8 MHz for an invalid channel bandwidth

From: YuanZhe Liu

Date: Sat Nov 21 2026 - 13:21:00 EST


dib7000p_update_timf() derives the new TIMF value from the channel
bandwidth:

state->timf = timf * 160 / (state->current_bandwidth / 50);

current_bandwidth is the bandwidth userspace asked for through
FE_SET_FRONTEND or DTV_BANDWIDTH_HZ, in kHz. Zero is a value the
driver can be handed: dtv_property_cache_sync() maps the legacy
BANDWIDTH_AUTO to bandwidth_hz = 0, and its OFDM bandwidth switch has no
default branch, so an out-of-range bandwidth leaves the cached value
untouched, which is zero until a valid one is set. Tuning then divides
by zero once the demodulator reports a lock:

divide error: 0000 [#1] SMP KASAN
RIP: dib7000p_update_timf+0x85/0x1e0
...
dib7000p_tune
dib7000p_set_frontend
dvb_frontend_swzigzag_autotune

dib7000p_spur_protect() divides by the bandwidth as well, after rounding
it down to 100 kHz units, for the devices that enable spur protection.

The demodulator is reset with an 8 MHz bandwidth and dib7000m falls back
to that value for a zero bandwidth, but dib7000p never got the same
handling when both drivers were converted to the DVBv5 parameters: the
old BANDWIDTH_TO_KHZ() mapped a bandwidth it did not know to 8000, the
new one divides by 1000 and returns 0, and only dib7000m was given the
fallback. The same divide error has been reported on real hardware with
kernels 3.10 and 3.19 but was never fixed.

Use the 8 MHz default when the requested bandwidth is zero or below the
granularity used by those two divisions.

Reported-by: gary smith <kaisersose77x@xxxxxxxxx>
Closes: https://lore.kernel.org/r/CA%2BfUvsiNVBvo3%2BfjvDcQr0Rc%3DPp5pQA1qL_cYq46NCN5z5K%3D6g@xxxxxxxxxxxxxx
Reported-by: Adam Baker <linux@xxxxxxxxxxxxxxxx>
Closes: https://lore.kernel.org/r/550B4F8D.7070905@xxxxxxxxxxxxxxxx
Fixes: c1f814f49904a ("[media] dibx000: convert set_fontend to use DVBv5 parameters")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/media/dvb-frontends/dib7000p.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/media/dvb-frontends/dib7000p.c b/drivers/media/dvb-frontends/dib7000p.c
index 48d84a05ddfa..dd3181aed2e4 100644
--- a/drivers/media/dvb-frontends/dib7000p.c
+++ b/drivers/media/dvb-frontends/dib7000p.c
@@ -1515,6 +1515,20 @@ static int dib7000p_set_frontend(struct dvb_frontend *fe)
struct dib7000p_state *state = fe->demodulator_priv;
int time, ret;

+ /*
+ * dib7000p_tune() scales its TIMF and spur protection settings
+ * with the channel bandwidth and divides by it: by bandwidth / 50
+ * in dib7000p_update_timf() and by bandwidth / 100 in
+ * dib7000p_spur_protect(). A zero bandwidth, which is what the
+ * legacy BANDWIDTH_AUTO and an out-of-range bandwidth from
+ * dtv_property_cache_sync() leave in the cache, or one below that
+ * resolution, divides by zero. Fall back to the 8 MHz default
+ * the demodulator is reset with, as dib7000m does for a zero
+ * bandwidth.
+ */
+ if (fep->bandwidth_hz < 100000)
+ fep->bandwidth_hz = 8000000;
+
if (state->version == SOC7090)
dib7090_set_diversity_in(fe, 0);
else
--
2.34.1