* fix compile-time divide-by-zero in scsi_ioctl
@ 2006-09-26 15:48 David Brownell
2006-09-27 20:27 ` Matthew Wilcox
0 siblings, 1 reply; 4+ messages in thread
From: David Brownell @ 2006-09-26 15:48 UTC (permalink / raw)
To: linux-scsi
This fixes a compiler-reported divide-by-zero when HZ < 100.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Index: at91/block/scsi_ioctl.c
===================================================================
--- at91.orig/block/scsi_ioctl.c 2006-07-30 01:17:34.000000000 -0700
+++ at91/block/scsi_ioctl.c 2006-07-30 01:44:17.000000000 -0700
@@ -63,7 +63,7 @@ static int scsi_get_bus(request_queue_t
static int sg_get_timeout(request_queue_t *q)
{
- return q->sg_timeout / (HZ / USER_HZ);
+ return q->sg_timeout / max(1,(HZ / USER_HZ));
}
static int sg_set_timeout(request_queue_t *q, int __user *p)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fix compile-time divide-by-zero in scsi_ioctl
2006-09-26 15:48 fix compile-time divide-by-zero in scsi_ioctl David Brownell
@ 2006-09-27 20:27 ` Matthew Wilcox
2006-09-27 23:28 ` David Brownell
0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2006-09-27 20:27 UTC (permalink / raw)
To: David Brownell; +Cc: linux-scsi
On Tue, Sep 26, 2006 at 08:48:48AM -0700, David Brownell wrote:
> This fixes a compiler-reported divide-by-zero when HZ < 100.
Shouldn't we instead be using jiffies_to_clock_t? Thus:
Index: at91/block/scsi_ioctl.c
===================================================================
--- at91.orig/block/scsi_ioctl.c 2006-07-30 01:17:34.000000000 -0700
+++ at91/block/scsi_ioctl.c 2006-07-30 01:44:17.000000000 -0700
@@ -63,7 +63,7 @@ static int scsi_get_bus(request_queue_t
static int sg_get_timeout(request_queue_t *q)
{
- return q->sg_timeout / (HZ / USER_HZ);
+ return jiffies_to_clock_t(q->sg_timeout);
}
static int sg_set_timeout(request_queue_t *q, int __user *p)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fix compile-time divide-by-zero in scsi_ioctl
2006-09-27 20:27 ` Matthew Wilcox
@ 2006-09-27 23:28 ` David Brownell
2006-09-28 2:40 ` Matthew Wilcox
0 siblings, 1 reply; 4+ messages in thread
From: David Brownell @ 2006-09-27 23:28 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-scsi
On Wednesday 27 September 2006 1:27 pm, Matthew Wilcox wrote:
> On Tue, Sep 26, 2006 at 08:48:48AM -0700, David Brownell wrote:
> > This fixes a compiler-reported divide-by-zero when HZ < 100.
>
> Shouldn't we instead be using jiffies_to_clock_t? Thus:
Could be ... the units in that function unclear to me though.
What I care about is not needing to carry a patch around in my tree ...
I got no response when I posted a fix to LKML several months back,
your suggestion could well be better!
FWIW HZ=64 can be convenient for various embedded platforms with
32768/sec system clocks; HZ=100 can be impractical.
- Dave
> Index: at91/block/scsi_ioctl.c
> ===================================================================
> --- at91.orig/block/scsi_ioctl.c 2006-07-30 01:17:34.000000000 -0700
> +++ at91/block/scsi_ioctl.c 2006-07-30 01:44:17.000000000 -0700
> @@ -63,7 +63,7 @@ static int scsi_get_bus(request_queue_t
>
> static int sg_get_timeout(request_queue_t *q)
> {
> - return q->sg_timeout / (HZ / USER_HZ);
> + return jiffies_to_clock_t(q->sg_timeout);
> }
>
> static int sg_set_timeout(request_queue_t *q, int __user *p)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fix compile-time divide-by-zero in scsi_ioctl
2006-09-27 23:28 ` David Brownell
@ 2006-09-28 2:40 ` Matthew Wilcox
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2006-09-28 2:40 UTC (permalink / raw)
To: David Brownell; +Cc: linux-scsi
On Wed, Sep 27, 2006 at 04:28:26PM -0700, David Brownell wrote:
> On Wednesday 27 September 2006 1:27 pm, Matthew Wilcox wrote:
> > On Tue, Sep 26, 2006 at 08:48:48AM -0700, David Brownell wrote:
> > > This fixes a compiler-reported divide-by-zero when HZ < 100.
> >
> > Shouldn't we instead be using jiffies_to_clock_t? Thus:
>
> Could be ... the units in that function unclear to me though.
Me too, tbh. But the function looks right.
static inline clock_t jiffies_to_clock_t(long x)
{
#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
return x / (HZ / USER_HZ);
#else
u64 tmp = (u64)x * TICK_NSEC;
do_div(tmp, (NSEC_PER_SEC / USER_HZ));
return (long)tmp;
#endif
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-09-28 2:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-26 15:48 fix compile-time divide-by-zero in scsi_ioctl David Brownell
2006-09-27 20:27 ` Matthew Wilcox
2006-09-27 23:28 ` David Brownell
2006-09-28 2:40 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox