staging: comedi: drivers: ni_mio_common: Prefer using macro DIV_ROUND_UP
authorBhaktipriya Shridhar <bhaktipriya96@gmail.com>
Wed, 9 Mar 2016 18:35:16 +0000 (00:05 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Mar 2016 03:34:22 +0000 (19:34 -0800)
The macro DIV_ROUND_UP performs the computation
(((n) + (d) - 1) /(d)). It clarifies the divisor calculations.
This was done using the coccinelle script:
@@
expression e1;
expression e2;
@@
(
- ((e1) + e2 - 1) / (e2)
+ DIV_ROUND_UP(e1,e2)
|
- ((e1) + (e2 - 1)) / (e2)
+ DIV_ROUND_UP(e1,e2)
)

Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_mio_common.c

index 8d8535b..d1226c9 100644 (file)
@@ -2058,7 +2058,7 @@ static int ni_ns_to_timer(const struct comedi_device *dev, unsigned nanosec,
                divider = (nanosec) / devpriv->clock_ns;
                break;
        case CMDF_ROUND_UP:
-               divider = (nanosec + devpriv->clock_ns - 1) / devpriv->clock_ns;
+               divider = DIV_ROUND_UP(nanosec, devpriv->clock_ns);
                break;
        }
        return divider - 1;
@@ -4241,8 +4241,7 @@ static int ni_m_series_pwm_config(struct comedi_device *dev,
                        break;
                case CMDF_ROUND_UP:
                        up_count =
-                           (data[2] + devpriv->clock_ns -
-                            1) / devpriv->clock_ns;
+                           DIV_ROUND_UP(data[2], devpriv->clock_ns);
                        break;
                default:
                        return -EINVAL;
@@ -4257,8 +4256,7 @@ static int ni_m_series_pwm_config(struct comedi_device *dev,
                        break;
                case CMDF_ROUND_UP:
                        down_count =
-                           (data[4] + devpriv->clock_ns -
-                            1) / devpriv->clock_ns;
+                           DIV_ROUND_UP(data[4], devpriv->clock_ns);
                        break;
                default:
                        return -EINVAL;
@@ -4303,8 +4301,7 @@ static int ni_6143_pwm_config(struct comedi_device *dev,
                        break;
                case CMDF_ROUND_UP:
                        up_count =
-                           (data[2] + devpriv->clock_ns -
-                            1) / devpriv->clock_ns;
+                           DIV_ROUND_UP(data[2], devpriv->clock_ns);
                        break;
                default:
                        return -EINVAL;
@@ -4319,8 +4316,7 @@ static int ni_6143_pwm_config(struct comedi_device *dev,
                        break;
                case CMDF_ROUND_UP:
                        down_count =
-                           (data[4] + devpriv->clock_ns -
-                            1) / devpriv->clock_ns;
+                           DIV_ROUND_UP(data[4], devpriv->clock_ns);
                        break;
                default:
                        return -EINVAL;