* [PATCH 6/6] staging: comedi: Using macro DIV_ROUND_UP
@ 2017-02-21 18:28 simran singhal
2017-03-08 12:57 ` Ian Abbott
0 siblings, 1 reply; 2+ messages in thread
From: simran singhal @ 2017-02-21 18:28 UTC (permalink / raw)
To: abbotti; +Cc: hsweeten, gregkh, devel, linux-kernel, outreachy-kernel
The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)).
It clarifies the divisor calculations. This occurence was detected 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: simran singhal <singhalsimran0@gmail.com>
---
drivers/staging/comedi/drivers/addi_apci_3xxx.c | 2 +-
drivers/staging/comedi/drivers/cb_pcidas64.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
index b6af3eb..82c2211 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
@@ -502,7 +502,7 @@ static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev,
timer = *ns / base;
break;
case CMDF_ROUND_UP:
- timer = (*ns + base - 1) / base;
+ timer = DIV_ROUND_UP(*ns, base);
break;
}
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index efbf277..3b98193 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -2007,7 +2007,7 @@ static unsigned int get_divisor(unsigned int ns, unsigned int flags)
switch (flags & CMDF_ROUND_MASK) {
case CMDF_ROUND_UP:
- divisor = (ns + TIMER_BASE - 1) / TIMER_BASE;
+ divisor = DIV_ROUND_UP(ns, TIMER_BASE);
break;
case CMDF_ROUND_DOWN:
divisor = ns / TIMER_BASE;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 6/6] staging: comedi: Using macro DIV_ROUND_UP
2017-02-21 18:28 [PATCH 6/6] staging: comedi: Using macro DIV_ROUND_UP simran singhal
@ 2017-03-08 12:57 ` Ian Abbott
0 siblings, 0 replies; 2+ messages in thread
From: Ian Abbott @ 2017-03-08 12:57 UTC (permalink / raw)
To: simran singhal; +Cc: hsweeten, gregkh, devel, linux-kernel, outreachy-kernel
On 21/02/17 18:28, simran singhal wrote:
> The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)).
> It clarifies the divisor calculations. This occurence was detected 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: simran singhal <singhalsimran0@gmail.com>
> ---
> drivers/staging/comedi/drivers/addi_apci_3xxx.c | 2 +-
> drivers/staging/comedi/drivers/cb_pcidas64.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
> index b6af3eb..82c2211 100644
> --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
> +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
> @@ -502,7 +502,7 @@ static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev,
> timer = *ns / base;
> break;
> case CMDF_ROUND_UP:
> - timer = (*ns + base - 1) / base;
> + timer = DIV_ROUND_UP(*ns, base);
> break;
> }
>
> diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
> index efbf277..3b98193 100644
> --- a/drivers/staging/comedi/drivers/cb_pcidas64.c
> +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
> @@ -2007,7 +2007,7 @@ static unsigned int get_divisor(unsigned int ns, unsigned int flags)
>
> switch (flags & CMDF_ROUND_MASK) {
> case CMDF_ROUND_UP:
> - divisor = (ns + TIMER_BASE - 1) / TIMER_BASE;
> + divisor = DIV_ROUND_UP(ns, TIMER_BASE);
> break;
> case CMDF_ROUND_DOWN:
> divisor = ns / TIMER_BASE;
>
Thanks. Ideally, this should be split into two patches, one for each
driver module, but I guess we can live with a single patch. (I don't
know about the other 5 patches in this series.)
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-08 12:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21 18:28 [PATCH 6/6] staging: comedi: Using macro DIV_ROUND_UP simran singhal
2017-03-08 12:57 ` Ian Abbott
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.