Re: [PATCH 1/2] HPET: disallow zero interrupt frequency

From: Clemens Ladisch
Date: Wed Sep 28 2005 - 01:52:03 EST


Bob Picco wrote:
> > - if (arg & (arg - 1)) {
> > + if (arg < 1 || (arg & (arg - 1))) {
>
> Well it seems like what you want is:
>
> if (!arg || (arg & (arg - 1))) {

Yes, it's the same. Here's the new patch:

Disallow setting an interrupt frequency of zero (which would result in
a division by zero), and disallow enabling the interrupt when the
frequency hasn't yet been set (which would use an interrupt period of
zero).

Signed-off-by: Clemens Ladisch <clemens@xxxxxxxxxx>
--- linux-2.6.13.orig/drivers/char/hpet.c 2005-09-22 10:56:23.000000000 +0200
+++ linux-2.6.13/drivers/char/hpet.c 2005-09-25 19:02:02.000000000 +0200
@@ -365,6 +365,9 @@ static int hpet_ioctl_ieon(struct hpet_d
hpet = devp->hd_hpet;
hpetp = devp->hd_hpets;

+ if (!devp->hd_ireqfreq)
+ return -EIO;
+
v = readq(&timer->hpet_config);
spin_lock_irq(&hpet_lock);

@@ -517,7 +520,7 @@ hpet_ioctl_common(struct hpet_dev *devp,
break;
}

- if (arg & (arg - 1)) {
+ if (!arg || (arg & (arg - 1))) {
err = -EINVAL;
break;
}