diff options
author | Bhaktipriya Shridhar <bhaktipriya96@gmail.com> | 2016-02-21 16:13:01 +0530 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-03-05 14:56:55 -0800 |
commit | 1e5a05d57c2a103903e6980c86057870666a9ac8 (patch) | |
tree | 6c1a0e9b4f0dea7e31ade6a35c673c92fa22a3fc | |
parent | 5ee5ae02669f3bfc62a28f6cced596a00ca17803 (diff) | |
download | linux-1e5a05d57c2a103903e6980c86057870666a9ac8.tar.bz2 |
staging: comedi: Use macro DIV_ROUND_CLOSEST
Occurences of the computation (x +d/2)/d can be replaced with
the macro DIV_ROUND_CLOSEST.
This was detected by the following Coccinelle script.
@@
expression e1,e2;
@@
(
- ((e1) + e2/2) / (e2)
+ DIV_ROUND_CLOSEST(e1,e2)
|
- ((e1) + (e2/2)) / (e2)
+ DIV_ROUND_CLOSEST(e1,e2)
)
Since some lines exceeded the 80 character limit,
some changes were made by hand.
Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/ni_mio_common.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 1c2abb3feb42..8d8535b1b6ca 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -2052,7 +2052,7 @@ static int ni_ns_to_timer(const struct comedi_device *dev, unsigned nanosec, switch (flags & CMDF_ROUND_MASK) { case CMDF_ROUND_NEAREST: default: - divider = (nanosec + devpriv->clock_ns / 2) / devpriv->clock_ns; + divider = DIV_ROUND_CLOSEST(nanosec, devpriv->clock_ns); break; case CMDF_ROUND_DOWN: divider = (nanosec) / devpriv->clock_ns; @@ -4233,9 +4233,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev, case INSN_CONFIG_PWM_OUTPUT: switch (data[1]) { case CMDF_ROUND_NEAREST: - up_count = - (data[2] + - devpriv->clock_ns / 2) / devpriv->clock_ns; + up_count = DIV_ROUND_CLOSEST(data[2], + devpriv->clock_ns); break; case CMDF_ROUND_DOWN: up_count = data[2] / devpriv->clock_ns; @@ -4250,9 +4249,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev, } switch (data[3]) { case CMDF_ROUND_NEAREST: - down_count = - (data[4] + - devpriv->clock_ns / 2) / devpriv->clock_ns; + down_count = DIV_ROUND_CLOSEST(data[4], + devpriv->clock_ns); break; case CMDF_ROUND_DOWN: down_count = data[4] / devpriv->clock_ns; @@ -4297,9 +4295,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev, case INSN_CONFIG_PWM_OUTPUT: switch (data[1]) { case CMDF_ROUND_NEAREST: - up_count = - (data[2] + - devpriv->clock_ns / 2) / devpriv->clock_ns; + up_count = DIV_ROUND_CLOSEST(data[2], + devpriv->clock_ns); break; case CMDF_ROUND_DOWN: up_count = data[2] / devpriv->clock_ns; @@ -4314,9 +4311,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev, } switch (data[3]) { case CMDF_ROUND_NEAREST: - down_count = - (data[4] + - devpriv->clock_ns / 2) / devpriv->clock_ns; + down_count = DIV_ROUND_CLOSEST(data[4], + devpriv->clock_ns); break; case CMDF_ROUND_DOWN: down_count = data[4] / devpriv->clock_ns; @@ -4918,9 +4914,9 @@ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns, *freq_divider = best_div; *freq_multiplier = best_mult; - *actual_period_ns = - (best_period_picosec * fudge_factor_80_to_20Mhz + - (pico_per_nano / 2)) / pico_per_nano; + *actual_period_ns = DIV_ROUND_CLOSEST(best_period_picosec * + fudge_factor_80_to_20Mhz, + pico_per_nano); return 0; } |