rtc: make rtc_update_irq callable with irqs enabled
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Thu, 18 Jun 2009 23:49:09 +0000 (16:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 19 Jun 2009 23:46:05 +0000 (16:46 -0700)
The rtc_update_irq() might be called with irqs enabled, if a interrupt
handler was registered without IRQF_DISABLED.  Use
spin_lock_irqsave/spin_unlock_irqrestore instead of spin_lock/spin_unlock.

Also update kerneldoc and drivers which do extra work to follow the
current interface spec, as suggestted by David Brownell.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/interface.c
drivers/rtc/rtc-dev.c
drivers/rtc/rtc-ds1305.c
drivers/rtc/rtc-ds1307.c
drivers/rtc/rtc-ds1374.c
drivers/rtc/rtc-test.c

index 4348c4b0d4536dde8fb556ad3fe34cfc2f37b611..4cdb31a362ca010e9d6c39aa7d332f683ed0f10a 100644 (file)
@@ -371,19 +371,21 @@ EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
  * @rtc: the rtc device
  * @num: how many irqs are being reported (usually one)
  * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
- * Context: in_interrupt(), irqs blocked
+ * Context: any
  */
 void rtc_update_irq(struct rtc_device *rtc,
                unsigned long num, unsigned long events)
 {
-       spin_lock(&rtc->irq_lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&rtc->irq_lock, flags);
        rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
-       spin_unlock(&rtc->irq_lock);
+       spin_unlock_irqrestore(&rtc->irq_lock, flags);
 
-       spin_lock(&rtc->irq_task_lock);
+       spin_lock_irqsave(&rtc->irq_task_lock, flags);
        if (rtc->irq_task)
                rtc->irq_task->func(rtc->irq_task->private_data);
-       spin_unlock(&rtc->irq_task_lock);
+       spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
 
        wake_up_interruptible(&rtc->irq_queue);
        kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
index 45152f4952d66f5d28a99211f7e6e71d09649e12..8a11de9552cd06427e222f8eaba23409f3b49476 100644 (file)
@@ -60,8 +60,7 @@ static void rtc_uie_task(struct work_struct *work)
 
        err = rtc_read_time(rtc, &tm);
 
-       local_irq_disable();
-       spin_lock(&rtc->irq_lock);
+       spin_lock_irq(&rtc->irq_lock);
        if (rtc->stop_uie_polling || err) {
                rtc->uie_task_active = 0;
        } else if (rtc->oldsecs != tm.tm_sec) {
@@ -74,10 +73,9 @@ static void rtc_uie_task(struct work_struct *work)
        } else if (schedule_work(&rtc->uie_task) == 0) {
                rtc->uie_task_active = 0;
        }
-       spin_unlock(&rtc->irq_lock);
+       spin_unlock_irq(&rtc->irq_lock);
        if (num)
                rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF);
-       local_irq_enable();
 }
 static void rtc_uie_timer(unsigned long data)
 {
index fc372df6534b5e93b3296913be692188cd5c1d41..8f410e59d9f536583c4a1509e65b2ecacd70bbcd 100644 (file)
@@ -499,10 +499,7 @@ static void ds1305_work(struct work_struct *work)
        if (!test_bit(FLAG_EXITING, &ds1305->flags))
                enable_irq(spi->irq);
 
-       /* rtc_update_irq() requires an IRQ-disabled context */
-       local_irq_disable();
        rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
-       local_irq_enable();
 }
 
 /*
index 8a6f9a9f9cb83d98c8e5b6e20a8da8c8374bb004..47a93c022d91b20bc840bd8158bb1097514eaa7b 100644 (file)
@@ -267,12 +267,7 @@ static void ds1307_work(struct work_struct *work)
                control &= ~DS1337_BIT_A1IE;
                i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control);
 
-               /* rtc_update_irq() assumes that it is called
-                * from IRQ-disabled context.
-                */
-               local_irq_disable();
                rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
-               local_irq_enable();
        }
 
 out:
index 4d32e328f6cd6b7bb2e9cf9e72748b6031f30ef6..32b27739ec2a4567acd1d2cb2e38535c385d4f27 100644 (file)
@@ -296,12 +296,7 @@ static void ds1374_work(struct work_struct *work)
                control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE);
                i2c_smbus_write_byte_data(client, DS1374_REG_CR, control);
 
-               /* rtc_update_irq() assumes that it is called
-                * from IRQ-disabled context.
-                */
-               local_irq_disable();
                rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF);
-               local_irq_enable();
        }
 
 out:
index e478280ff6283d130c9cd456d09189a17f5f472c..51725f7755b08ca8ec7dbc221d4d9e8d03bbde52 100644 (file)
@@ -93,7 +93,6 @@ static ssize_t test_irq_store(struct device *dev,
        struct rtc_device *rtc = platform_get_drvdata(plat_dev);
 
        retval = count;
-       local_irq_disable();
        if (strncmp(buf, "tick", 4) == 0)
                rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
        else if (strncmp(buf, "alarm", 5) == 0)
@@ -102,7 +101,6 @@ static ssize_t test_irq_store(struct device *dev,
                rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
        else
                retval = -EINVAL;
-       local_irq_enable();
 
        return retval;
 }