The patch number 12483 was added via Mauro Carvalho Chehab <mche...@redhat.com>
to http://linuxtv.org/hg/v4l-dvb master development tree.

Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel

If anyone has any objections, please let us know by sending a message to:
        Linux Media Mailing List <linux-me...@vger.kernel.org>

------

From: Julia Lawall  <ju...@diku.dk>
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 <ju...@diku.dk>
Signed-off-by: Mauro Carvalho Chehab <mche...@redhat.com>


---

 linux/drivers/media/dvb/frontends/dib7000p.c |    2 +-
 linux/drivers/media/dvb/frontends/stb6100.c  |    4 +++-
 linux/drivers/media/dvb/frontends/tda10021.c |    2 +-
 linux/drivers/media/dvb/frontends/ves1820.c  |    2 +-
 linux/drivers/media/dvb/pluto2/pluto2.c      |    2 +-
 linux/drivers/media/video/tuner-core.c       |    4 ++--
 linux/drivers/media/video/v4l1-compat.c      |    5 ++---
 7 files changed, 11 insertions(+), 10 deletions(-)

diff -r fcc0fc5a53cd -r ff98058bfb86 
linux/drivers/media/dvb/frontends/dib7000p.c
--- a/linux/drivers/media/dvb/frontends/dib7000p.c      Sat Aug 01 11:02:38 
2009 +0000
+++ b/linux/drivers/media/dvb/frontends/dib7000p.c      Sat Aug 01 19:48:41 
2009 +0000
@@ -909,7 +909,7 @@
        255, 255, 255, 255, 255, 255};
 
        u32 xtal = state->cfg.bw->xtal_hz / 1000;
-       int f_rel = ( (rf_khz + xtal/2) / xtal) * xtal - rf_khz;
+       int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz;
        int k;
        int coef_re[8],coef_im[8];
        int bw_khz = bw;
diff -r fcc0fc5a53cd -r ff98058bfb86 linux/drivers/media/dvb/frontends/stb6100.c
--- a/linux/drivers/media/dvb/frontends/stb6100.c       Sat Aug 01 11:02:38 
2009 +0000
+++ b/linux/drivers/media/dvb/frontends/stb6100.c       Sat Aug 01 19:48:41 
2009 +0000
@@ -374,7 +374,9 @@
        /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1)))    */
        nint = fvco / (state->reference << psd2);
        /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9       
*/
-       nfrac = (((fvco - (nint * state->reference << psd2)) << (9 - psd2)) + 
state->reference / 2) / state->reference;
+       nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
+                                        << (9 - psd2),
+                                 state->reference);
        dprintk(verbose, FE_DEBUG, 1,
                "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, 
fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
                frequency, srate, (unsigned int)g, (unsigned int)odiv,
diff -r fcc0fc5a53cd -r ff98058bfb86 
linux/drivers/media/dvb/frontends/tda10021.c
--- a/linux/drivers/media/dvb/frontends/tda10021.c      Sat Aug 01 11:02:38 
2009 +0000
+++ b/linux/drivers/media/dvb/frontends/tda10021.c      Sat Aug 01 19:48:41 
2009 +0000
@@ -176,7 +176,7 @@
        tmp =  ((symbolrate << 4) % FIN) << 8;
        ratio = (ratio << 8) + tmp / FIN;
        tmp = (tmp % FIN) << 8;
-       ratio = (ratio << 8) + (tmp + FIN/2) / FIN;
+       ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, FIN);
 
        BDR = ratio;
        BDRI = (((XIN << 5) / symbolrate) + 1) / 2;
diff -r fcc0fc5a53cd -r ff98058bfb86 linux/drivers/media/dvb/frontends/ves1820.c
--- a/linux/drivers/media/dvb/frontends/ves1820.c       Sat Aug 01 11:02:38 
2009 +0000
+++ b/linux/drivers/media/dvb/frontends/ves1820.c       Sat Aug 01 19:48:41 
2009 +0000
@@ -165,7 +165,7 @@
        tmp = ((symbolrate << 4) % fin) << 8;
        ratio = (ratio << 8) + tmp / fin;
        tmp = (tmp % fin) << 8;
-       ratio = (ratio << 8) + (tmp + fin / 2) / fin;
+       ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, fin);
 
        BDR = ratio;
        BDRI = (((state->config->xin << 5) / symbolrate) + 1) / 2;
diff -r fcc0fc5a53cd -r ff98058bfb86 linux/drivers/media/dvb/pluto2/pluto2.c
--- a/linux/drivers/media/dvb/pluto2/pluto2.c   Sat Aug 01 11:02:38 2009 +0000
+++ b/linux/drivers/media/dvb/pluto2/pluto2.c   Sat Aug 01 19:48:41 2009 +0000
@@ -447,7 +447,7 @@
        if (denominator == 0)
                return ~0;
 
-       return (numerator + denominator / 2) / denominator;
+       return DIV_ROUND_CLOSEST(numerator, denominator);
 }
 
 /* LG Innotek TDTE-E001P (Infineon TUA6034) */
diff -r fcc0fc5a53cd -r ff98058bfb86 linux/drivers/media/video/tuner-core.c
--- a/linux/drivers/media/video/tuner-core.c    Sat Aug 01 11:02:38 2009 +0000
+++ b/linux/drivers/media/video/tuner-core.c    Sat Aug 01 19:48:41 2009 +0000
@@ -842,8 +842,8 @@
 
                fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
                f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
-                       (abs_freq * 2 + 125/2) / 125 :
-                       (abs_freq + 62500/2) / 62500;
+                       DIV_ROUND_CLOSEST(abs_freq * 2, 125) :
+                       DIV_ROUND_CLOSEST(abs_freq, 62500);
                return 0;
        }
        f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
diff -r fcc0fc5a53cd -r ff98058bfb86 linux/drivers/media/video/v4l1-compat.c
--- a/linux/drivers/media/video/v4l1-compat.c   Sat Aug 01 11:02:38 2009 +0000
+++ b/linux/drivers/media/video/v4l1-compat.c   Sat Aug 01 19:48:41 2009 +0000
@@ -77,9 +77,8 @@
                        dprintk("VIDIOC_G_CTRL: %d\n", err);
                        return 0;
                }
-               return ((ctrl2.value - qctrl2.minimum) * 65535
-                        + (qctrl2.maximum - qctrl2.minimum) / 2)
-                       / (qctrl2.maximum - qctrl2.minimum);
+               return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535,
+                                        qctrl2.maximum - qctrl2.minimum);
        }
        return 0;
 }


---

Patch is available at: 
http://linuxtv.org/hg/v4l-dvb/rev/ff98058bfb8676eb90921745f24ca82c4147ea44

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to