[ALSA] Fix thinko in cs4231 mce down check
authorTakashi Iwai <tiwai@suse.de>
Tue, 11 Sep 2007 08:12:14 +0000 (10:12 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Oct 2007 14:52:12 +0000 (16:52 +0200)
The last patches to replace with schedule_timeout() don't work as expected.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
sound/isa/cs423x/cs4231_lib.c
sound/sparc/cs4231.c

index 72cf771590838bf039d6fbf3e558b5bf37adb8b5..a5eb9659b519ca8003034651654d9bef5bb98af9 100644 (file)
@@ -313,6 +313,7 @@ void snd_cs4231_mce_up(struct snd_cs4231 *chip)
 void snd_cs4231_mce_down(struct snd_cs4231 *chip)
 {
        unsigned long flags;
 void snd_cs4231_mce_down(struct snd_cs4231 *chip)
 {
        unsigned long flags;
+       unsigned long end_time;
        int timeout;
 
        snd_cs4231_busy_wait(chip);
        int timeout;
 
        snd_cs4231_busy_wait(chip);
@@ -344,28 +345,28 @@ void snd_cs4231_mce_down(struct snd_cs4231 *chip)
        snd_printdd("(1) jiffies = %lu\n", jiffies);
 
        /* check condition up to 250 ms */
        snd_printdd("(1) jiffies = %lu\n", jiffies);
 
        /* check condition up to 250 ms */
-       timeout = msecs_to_jiffies(250);
+       end_time = jiffies + msecs_to_jiffies(250);
        while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
                CS4231_CALIB_IN_PROGRESS) {
 
        while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
                CS4231_CALIB_IN_PROGRESS) {
 
-               if (timeout <= 0) {
+               if (time_after(jiffies, end_time)) {
                        snd_printk(KERN_ERR "mce_down - "
                                        "auto calibration time out (2)\n");
                        return;
                }
                        snd_printk(KERN_ERR "mce_down - "
                                        "auto calibration time out (2)\n");
                        return;
                }
-               timeout = schedule_timeout(timeout);
+               msleep(1);
        }
 
        snd_printdd("(2) jiffies = %lu\n", jiffies);
 
        /* check condition up to 100 ms */
        }
 
        snd_printdd("(2) jiffies = %lu\n", jiffies);
 
        /* check condition up to 100 ms */
-       timeout = msecs_to_jiffies(100);
+       end_time = jiffies + msecs_to_jiffies(100);
        while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
        while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
-               if (timeout <= 0) {
+               if (time_after(jiffies, end_time)) {
                        snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
                        return;
                }
                        snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
                        return;
                }
-               timeout = schedule_timeout(timeout);
+               msleep(1);
        }
 
        snd_printdd("(3) jiffies = %lu\n", jiffies);
        }
 
        snd_printdd("(3) jiffies = %lu\n", jiffies);
index ab39860e240418ee8219279ecc3545f96165786e..9785382a5f39fc6b6f125adc00600eb0432cc101 100644 (file)
@@ -401,6 +401,7 @@ static void snd_cs4231_mce_up(struct snd_cs4231 *chip)
 static void snd_cs4231_mce_down(struct snd_cs4231 *chip)
 {
        unsigned long flags;
 static void snd_cs4231_mce_down(struct snd_cs4231 *chip)
 {
        unsigned long flags;
+       unsigned long end_time;
        int timeout;
 
        spin_lock_irqsave(&chip->lock, flags);
        int timeout;
 
        spin_lock_irqsave(&chip->lock, flags);
@@ -431,30 +432,30 @@ static void snd_cs4231_mce_down(struct snd_cs4231 *chip)
        msleep(1);
 
        /* check condition up to 250ms */
        msleep(1);
 
        /* check condition up to 250ms */
-       timeout = msecs_to_jiffies(250);
+       end_time = jiffies + msecs_to_jiffies(250);
        while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
                CS4231_CALIB_IN_PROGRESS) {
 
                spin_unlock_irqrestore(&chip->lock, flags);
        while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
                CS4231_CALIB_IN_PROGRESS) {
 
                spin_unlock_irqrestore(&chip->lock, flags);
-               if (timeout <= 0) {
+               if (time_after(jiffies, end_time)) {
                        snd_printk("mce_down - "
                                   "auto calibration time out (2)\n");
                        return;
                }
                        snd_printk("mce_down - "
                                   "auto calibration time out (2)\n");
                        return;
                }
-               timeout = schedule_timeout(timeout);
+               msleep(1);
                spin_lock_irqsave(&chip->lock, flags);
        }
 
        /* check condition up to 100ms */
                spin_lock_irqsave(&chip->lock, flags);
        }
 
        /* check condition up to 100ms */
-       timeout = msecs_to_jiffies(100);
+       end_time = jiffies + msecs_to_jiffies(100);
        while (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) {
                spin_unlock_irqrestore(&chip->lock, flags);
        while (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) {
                spin_unlock_irqrestore(&chip->lock, flags);
-               if (timeout <= 0) {
+               if (time_after(jiffies, end_time)) {
                        snd_printk("mce_down - "
                                   "auto calibration time out (3)\n");
                        return;
                }
                        snd_printk("mce_down - "
                                   "auto calibration time out (3)\n");
                        return;
                }
-               timeout = schedule_timeout(timeout);
+               msleep(1);
                spin_lock_irqsave(&chip->lock, flags);
        }
        spin_unlock_irqrestore(&chip->lock, flags);
                spin_lock_irqsave(&chip->lock, flags);
        }
        spin_unlock_irqrestore(&chip->lock, flags);