* [patch 15/17] drivers/scsi: Use DIV_ROUND_UP
@ 2008-09-22 21:56 akpm
2008-09-23 0:43 ` Matthew Wilcox
0 siblings, 1 reply; 4+ messages in thread
From: akpm @ 2008-09-22 21:56 UTC (permalink / raw)
To: James.Bottomley; +Cc: linux-scsi, akpm, julia
From: Julia Lawall <julia@diku.dk>
The kernel.h macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /
(d)) but is perhaps more readable.
An extract of the semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@haskernel@
@@
#include <linux/kernel.h>
@depends on haskernel@
expression n,d;
@@
(
- (n + d - 1) / d
+ DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+ DIV_ROUND_UP(n,d)
)
@depends on haskernel@
expression n,d;
@@
- DIV_ROUND_UP((n),d)
+ DIV_ROUND_UP(n,d)
@depends on haskernel@
expression n,d;
@@
- DIV_ROUND_UP(n,(d))
+ DIV_ROUND_UP(n,d)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/scsi/esp_scsi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff -puN drivers/scsi/esp_scsi.c~drivers-scsi-use-div_round_up drivers/scsi/esp_scsi.c
--- a/drivers/scsi/esp_scsi.c~drivers-scsi-use-div_round_up
+++ a/drivers/scsi/esp_scsi.c
@@ -1464,7 +1464,7 @@ static void esp_msgin_sdtr(struct esp *e
one_clock = esp->ccycle / 1000;
rounded_up = (period << 2);
- rounded_up = (rounded_up + one_clock - 1) / one_clock;
+ rounded_up = DIV_ROUND_UP(rounded_up, one_clock);
stp = rounded_up;
if (stp && esp->rev >= FAS236) {
if (stp >= 50)
_
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 15/17] drivers/scsi: Use DIV_ROUND_UP
2008-09-22 21:56 [patch 15/17] drivers/scsi: Use DIV_ROUND_UP akpm
@ 2008-09-23 0:43 ` Matthew Wilcox
2008-09-24 19:26 ` Julia Lawall
0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2008-09-23 0:43 UTC (permalink / raw)
To: akpm; +Cc: James.Bottomley, linux-scsi, julia
On Mon, Sep 22, 2008 at 02:56:51PM -0700, akpm@linux-foundation.org wrote:
>
> one_clock = esp->ccycle / 1000;
> rounded_up = (period << 2);
> - rounded_up = (rounded_up + one_clock - 1) / one_clock;
> + rounded_up = DIV_ROUND_UP(rounded_up, one_clock);
> stp = rounded_up;
> if (stp && esp->rev >= FAS236) {
> if (stp >= 50)
Is this not exactly equivalent to:
one_clock = esp->ccycle / 1000;
stp = DIV_ROUND_UP(period << 2, one_clock);
(rounded_up is local to this if condition).
--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 15/17] drivers/scsi: Use DIV_ROUND_UP
2008-09-23 0:43 ` Matthew Wilcox
@ 2008-09-24 19:26 ` Julia Lawall
2008-09-24 19:31 ` Matthew Wilcox
0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2008-09-24 19:26 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: akpm, James.Bottomley, linux-scsi
On Mon, 22 Sep 2008, Matthew Wilcox wrote:
> On Mon, Sep 22, 2008 at 02:56:51PM -0700, akpm@linux-foundation.org wrote:
> >
> > one_clock = esp->ccycle / 1000;
> > rounded_up = (period << 2);
> > - rounded_up = (rounded_up + one_clock - 1) / one_clock;
> > + rounded_up = DIV_ROUND_UP(rounded_up, one_clock);
> > stp = rounded_up;
> > if (stp && esp->rev >= FAS236) {
> > if (stp >= 50)
>
> Is this not exactly equivalent to:
>
> one_clock = esp->ccycle / 1000;
> stp = DIV_ROUND_UP(period << 2, one_clock);
>
> (rounded_up is local to this if condition).
Agreed. An updated patch is below.
julia
--------------------
From: Julia Lawall <julia@diku.dk>
Use the macro DIV_ROUND_UP and eliminate the variable rounded_up, as
suggested by Matthew Wilcox.
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/scsi/esp_scsi.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 62a4618..a680e18 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1453,7 +1453,7 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
offset = 0;
if (offset) {
- int rounded_up, one_clock;
+ int one_clock;
if (period > esp->max_period) {
period = offset = 0;
@@ -1463,9 +1463,7 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
goto do_reject;
one_clock = esp->ccycle / 1000;
- rounded_up = (period << 2);
- rounded_up = (rounded_up + one_clock - 1) / one_clock;
- stp = rounded_up;
+ stp = DIV_ROUND_UP(period << 2, one_clock);
if (stp && esp->rev >= FAS236) {
if (stp >= 50)
stp--;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch 15/17] drivers/scsi: Use DIV_ROUND_UP
2008-09-24 19:26 ` Julia Lawall
@ 2008-09-24 19:31 ` Matthew Wilcox
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2008-09-24 19:31 UTC (permalink / raw)
To: Julia Lawall; +Cc: akpm, James.Bottomley, linux-scsi
On Wed, Sep 24, 2008 at 09:26:48PM +0200, Julia Lawall wrote:
> --------------------
>
> From: Julia Lawall <julia@diku.dk>
>
> Use the macro DIV_ROUND_UP and eliminate the variable rounded_up, as
> suggested by Matthew Wilcox.
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
Reviewed-by: Matthew Wilcox <willy@linux.intel.com>
> ---
>
> drivers/scsi/esp_scsi.c | 6 ++----
> 1 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
> index 62a4618..a680e18 100644
> --- a/drivers/scsi/esp_scsi.c
> +++ b/drivers/scsi/esp_scsi.c
> @@ -1453,7 +1453,7 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
> offset = 0;
>
> if (offset) {
> - int rounded_up, one_clock;
> + int one_clock;
>
> if (period > esp->max_period) {
> period = offset = 0;
> @@ -1463,9 +1463,7 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
> goto do_reject;
>
> one_clock = esp->ccycle / 1000;
> - rounded_up = (period << 2);
> - rounded_up = (rounded_up + one_clock - 1) / one_clock;
> - stp = rounded_up;
> + stp = DIV_ROUND_UP(period << 2, one_clock);
> if (stp && esp->rev >= FAS236) {
> if (stp >= 50)
> stp--;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-24 19:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-22 21:56 [patch 15/17] drivers/scsi: Use DIV_ROUND_UP akpm
2008-09-23 0:43 ` Matthew Wilcox
2008-09-24 19:26 ` Julia Lawall
2008-09-24 19:31 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox