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

V4L/DVB (12483): Use DIV_ROUND_CLOSEST

The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@haskernel@
@@

@depends on haskernel@
expression x,__divisor;
@@

- (((x) + ((__divisor) / 2)) / (__divisor))
+ DIV_ROUND_CLOSEST(x,__divisor)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Julia Lawall and committed by
Mauro Carvalho Chehab
75b697f7 166987c6

+11 -10
+1 -1
drivers/media/dvb/frontends/dib7000p.c
··· 883 883 255, 255, 255, 255, 255, 255}; 884 884 885 885 u32 xtal = state->cfg.bw->xtal_hz / 1000; 886 - int f_rel = ( (rf_khz + xtal/2) / xtal) * xtal - rf_khz; 886 + int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz; 887 887 int k; 888 888 int coef_re[8],coef_im[8]; 889 889 int bw_khz = bw;
+3 -1
drivers/media/dvb/frontends/stb6100.c
··· 367 367 /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */ 368 368 nint = fvco / (state->reference << psd2); 369 369 /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */ 370 - nfrac = (((fvco - (nint * state->reference << psd2)) << (9 - psd2)) + state->reference / 2) / state->reference; 370 + nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2)) 371 + << (9 - psd2), 372 + state->reference); 371 373 dprintk(verbose, FE_DEBUG, 1, 372 374 "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u", 373 375 frequency, srate, (unsigned int)g, (unsigned int)odiv,
+1 -1
drivers/media/dvb/frontends/tda10021.c
··· 176 176 tmp = ((symbolrate << 4) % FIN) << 8; 177 177 ratio = (ratio << 8) + tmp / FIN; 178 178 tmp = (tmp % FIN) << 8; 179 - ratio = (ratio << 8) + (tmp + FIN/2) / FIN; 179 + ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, FIN); 180 180 181 181 BDR = ratio; 182 182 BDRI = (((XIN << 5) / symbolrate) + 1) / 2;
+1 -1
drivers/media/dvb/frontends/ves1820.c
··· 165 165 tmp = ((symbolrate << 4) % fin) << 8; 166 166 ratio = (ratio << 8) + tmp / fin; 167 167 tmp = (tmp % fin) << 8; 168 - ratio = (ratio << 8) + (tmp + fin / 2) / fin; 168 + ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, fin); 169 169 170 170 BDR = ratio; 171 171 BDRI = (((state->config->xin << 5) / symbolrate) + 1) / 2;
+1 -1
drivers/media/dvb/pluto2/pluto2.c
··· 439 439 if (denominator == 0) 440 440 return ~0; 441 441 442 - return (numerator + denominator / 2) / denominator; 442 + return DIV_ROUND_CLOSEST(numerator, denominator); 443 443 } 444 444 445 445 /* LG Innotek TDTE-E001P (Infineon TUA6034) */
+2 -2
drivers/media/video/tuner-core.c
··· 819 819 820 820 fe_tuner_ops->get_frequency(&t->fe, &abs_freq); 821 821 f->frequency = (V4L2_TUNER_RADIO == t->mode) ? 822 - (abs_freq * 2 + 125/2) / 125 : 823 - (abs_freq + 62500/2) / 62500; 822 + DIV_ROUND_CLOSEST(abs_freq * 2, 125) : 823 + DIV_ROUND_CLOSEST(abs_freq, 62500); 824 824 return 0; 825 825 } 826 826 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
+2 -3
drivers/media/video/v4l1-compat.c
··· 76 76 dprintk("VIDIOC_G_CTRL: %d\n", err); 77 77 return 0; 78 78 } 79 - return ((ctrl2.value - qctrl2.minimum) * 65535 80 - + (qctrl2.maximum - qctrl2.minimum) / 2) 81 - / (qctrl2.maximum - qctrl2.minimum); 79 + return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535, 80 + qctrl2.maximum - qctrl2.minimum); 82 81 } 83 82 return 0; 84 83 }