Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: cxd2841er: avoid too many status inquires

I2C ops are expensive, as the I2C bus typical speed is 100kbps.

Also, stats reading take some time, as it requires to retrieve a
certain number of packets to complete.

While we don't know the minimal for CXD2841er, trying to do it
too quickly is still a very bad idea.

So, add some sanity logic there, preventing to retrieve stats
faster than one second.

This shouldn't cause any issues with well behavior apps, as they
usually take stats on a polling rate slower than 1 second.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sean Young <sean@mess.org>

+11 -1
+11 -1
drivers/media/dvb-frontends/cxd2841er.c
··· 60 60 enum cxd2841er_xtal xtal; 61 61 enum fe_caps caps; 62 62 u32 flags; 63 + unsigned long stats_time; 63 64 }; 64 65 65 66 static const struct cxd2841er_cnr_data s_cn_data[] = { ··· 3280 3279 p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 3281 3280 3282 3281 if (status & FE_HAS_LOCK) { 3282 + if (priv->stats_time && 3283 + (!time_after(jiffies, priv->stats_time))) 3284 + return 0; 3285 + 3286 + /* Prevent retrieving stats faster than once per second */ 3287 + priv->stats_time = jiffies + msecs_to_jiffies(1000); 3288 + 3283 3289 cxd2841er_read_snr(fe); 3284 3290 cxd2841er_read_ucblocks(fe); 3285 - 3286 3291 cxd2841er_read_ber(fe); 3287 3292 } else { 3288 3293 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; ··· 3366 3359 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 3367 3360 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 3368 3361 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 3362 + 3363 + /* Reset the wait for jiffies logic */ 3364 + priv->stats_time = 0; 3369 3365 3370 3366 return ret; 3371 3367 }