]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
staging: comedi: drivers: Use DIV_ROUND_CLOSEST
authorAmitoj Kaur Chawla <amitoj1606@gmail.com>
Fri, 19 Feb 2016 15:27:15 +0000 (20:57 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Feb 2016 23:25:58 +0000 (15:25 -0800)
The kernel.h macro DIV_ROUND_CLOSEST performs the computation
`(x +d/2)/d` but is perhaps more readable.

The Coccinelle script used is as follows:
// <smpl>
@@
expression x,__divisor;
@@
- (((x) + ((__divisor) / 2)) / (__divisor))
+ DIV_ROUND_CLOSEST(x,__divisor)
// </smpl>

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/addi_apci_3xxx.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_pcidas64.c
drivers/staging/comedi/drivers/dt282x.c
drivers/staging/comedi/drivers/dt3000.c
drivers/staging/comedi/drivers/ni_pcidio.c

index 995096c78844f3a8199145251b05dfdc8695bab9..b6af3eba91fddeb3d1ec3c0a65a5ab79ddae8bd4 100644 (file)
@@ -496,7 +496,7 @@ static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev,
                switch (flags & CMDF_ROUND_MASK) {
                case CMDF_ROUND_NEAREST:
                default:
-                       timer = (*ns + base / 2) / base;
+                       timer = DIV_ROUND_CLOSEST(*ns, base);
                        break;
                case CMDF_ROUND_DOWN:
                        timer = *ns / base;
index 4b39f6960c0a6fba15ca00ecdf6003e8aac321f9..d1fe88a6133fb591f2461d0a02a84d262d615778 100644 (file)
@@ -637,7 +637,7 @@ static unsigned int pci230_divide_ns(uint64_t ns, unsigned int timebase,
        switch (flags & CMDF_ROUND_MASK) {
        default:
        case CMDF_ROUND_NEAREST:
-               div += (rem + (timebase / 2)) / timebase;
+               div += DIV_ROUND_CLOSEST(rem, timebase);
                break;
        case CMDF_ROUND_DOWN:
                break;
index d33b8fe872a723d2b16987c118bab6ccaa67629f..e918d4249629bd93ca0e0763ad40c7caad670c9a 100644 (file)
@@ -1376,7 +1376,7 @@ static int set_ai_fifo_segment_length(struct comedi_device *dev,
                num_entries = fifo->max_segment_length;
 
        /*  1 == 256 entries, 2 == 512 entries, etc */
-       num_increments = (num_entries + increment_size / 2) / increment_size;
+       num_increments = DIV_ROUND_CLOSEST(num_entries, increment_size);
 
        bits = (~(num_increments - 1)) & fifo->fifo_size_reg_mask;
        devpriv->fifo_size_bits &= ~fifo->fifo_size_reg_mask;
@@ -2004,7 +2004,7 @@ static unsigned int get_divisor(unsigned int ns, unsigned int flags)
                break;
        case CMDF_ROUND_NEAREST:
        default:
-               divisor = (ns + TIMER_BASE / 2) / TIMER_BASE;
+               divisor = DIV_ROUND_CLOSEST(ns, TIMER_BASE);
                break;
        }
        return divisor;
index 5a536a00066f9ff4340813d85b68854044715d3d..6c26e0924ebd3a099aa46d35ad9af2221c7db70b 100644 (file)
@@ -371,7 +371,7 @@ static unsigned int dt282x_ns_to_timer(unsigned int *ns, unsigned int flags)
                switch (flags & CMDF_ROUND_MASK) {
                case CMDF_ROUND_NEAREST:
                default:
-                       divider = (*ns + base / 2) / base;
+                       divider = DIV_ROUND_CLOSEST(*ns, base);
                        break;
                case CMDF_ROUND_DOWN:
                        divider = (*ns) / base;
index ab7a332fbcc46c7109472905ef613020d5c32f7c..19e0b7be8495fe7d6c70fe3ce616abcf938caa69 100644 (file)
@@ -361,7 +361,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec,
                switch (flags & CMDF_ROUND_MASK) {
                case CMDF_ROUND_NEAREST:
                default:
-                       divider = (*nanosec + base / 2) / base;
+                       divider = DIV_ROUND_CLOSEST(*nanosec, base);
                        break;
                case CMDF_ROUND_DOWN:
                        divider = (*nanosec) / base;
index ac79099bc23e4d94a09ad99cca01c352a8aacbc9..67b9f22074d2ff9b795773d48cf4dad8014560db 100644 (file)
@@ -525,7 +525,7 @@ static int ni_pcidio_ns_to_timer(int *nanosec, unsigned int flags)
        switch (flags & CMDF_ROUND_MASK) {
        case CMDF_ROUND_NEAREST:
        default:
-               divider = (*nanosec + base / 2) / base;
+               divider = DIV_ROUND_CLOSEST(*nanosec, base);
                break;
        case CMDF_ROUND_DOWN:
                divider = (*nanosec) / base;