Commit 1e5a05d5 authored by Bhaktipriya Shridhar's avatar Bhaktipriya Shridhar Committed by Greg Kroah-Hartman

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: default avatarBhaktipriya Shridhar <bhaktipriya96@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5ee5ae02
...@@ -2052,7 +2052,7 @@ static int ni_ns_to_timer(const struct comedi_device *dev, unsigned nanosec, ...@@ -2052,7 +2052,7 @@ static int ni_ns_to_timer(const struct comedi_device *dev, unsigned nanosec,
switch (flags & CMDF_ROUND_MASK) { switch (flags & CMDF_ROUND_MASK) {
case CMDF_ROUND_NEAREST: case CMDF_ROUND_NEAREST:
default: default:
divider = (nanosec + devpriv->clock_ns / 2) / devpriv->clock_ns; divider = DIV_ROUND_CLOSEST(nanosec, devpriv->clock_ns);
break; break;
case CMDF_ROUND_DOWN: case CMDF_ROUND_DOWN:
divider = (nanosec) / devpriv->clock_ns; divider = (nanosec) / devpriv->clock_ns;
...@@ -4233,9 +4233,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev, ...@@ -4233,9 +4233,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev,
case INSN_CONFIG_PWM_OUTPUT: case INSN_CONFIG_PWM_OUTPUT:
switch (data[1]) { switch (data[1]) {
case CMDF_ROUND_NEAREST: case CMDF_ROUND_NEAREST:
up_count = up_count = DIV_ROUND_CLOSEST(data[2],
(data[2] + devpriv->clock_ns);
devpriv->clock_ns / 2) / devpriv->clock_ns;
break; break;
case CMDF_ROUND_DOWN: case CMDF_ROUND_DOWN:
up_count = data[2] / devpriv->clock_ns; up_count = data[2] / devpriv->clock_ns;
...@@ -4250,9 +4249,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev, ...@@ -4250,9 +4249,8 @@ static int ni_m_series_pwm_config(struct comedi_device *dev,
} }
switch (data[3]) { switch (data[3]) {
case CMDF_ROUND_NEAREST: case CMDF_ROUND_NEAREST:
down_count = down_count = DIV_ROUND_CLOSEST(data[4],
(data[4] + devpriv->clock_ns);
devpriv->clock_ns / 2) / devpriv->clock_ns;
break; break;
case CMDF_ROUND_DOWN: case CMDF_ROUND_DOWN:
down_count = data[4] / devpriv->clock_ns; down_count = data[4] / devpriv->clock_ns;
...@@ -4297,9 +4295,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev, ...@@ -4297,9 +4295,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev,
case INSN_CONFIG_PWM_OUTPUT: case INSN_CONFIG_PWM_OUTPUT:
switch (data[1]) { switch (data[1]) {
case CMDF_ROUND_NEAREST: case CMDF_ROUND_NEAREST:
up_count = up_count = DIV_ROUND_CLOSEST(data[2],
(data[2] + devpriv->clock_ns);
devpriv->clock_ns / 2) / devpriv->clock_ns;
break; break;
case CMDF_ROUND_DOWN: case CMDF_ROUND_DOWN:
up_count = data[2] / devpriv->clock_ns; up_count = data[2] / devpriv->clock_ns;
...@@ -4314,9 +4311,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev, ...@@ -4314,9 +4311,8 @@ static int ni_6143_pwm_config(struct comedi_device *dev,
} }
switch (data[3]) { switch (data[3]) {
case CMDF_ROUND_NEAREST: case CMDF_ROUND_NEAREST:
down_count = down_count = DIV_ROUND_CLOSEST(data[4],
(data[4] + devpriv->clock_ns);
devpriv->clock_ns / 2) / devpriv->clock_ns;
break; break;
case CMDF_ROUND_DOWN: case CMDF_ROUND_DOWN:
down_count = data[4] / devpriv->clock_ns; down_count = data[4] / devpriv->clock_ns;
...@@ -4918,9 +4914,9 @@ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns, ...@@ -4918,9 +4914,9 @@ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns,
*freq_divider = best_div; *freq_divider = best_div;
*freq_multiplier = best_mult; *freq_multiplier = best_mult;
*actual_period_ns = *actual_period_ns = DIV_ROUND_CLOSEST(best_period_picosec *
(best_period_picosec * fudge_factor_80_to_20Mhz + fudge_factor_80_to_20Mhz,
(pico_per_nano / 2)) / pico_per_nano; pico_per_nano);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment