Commit e6229bec25be4ba00f31dd26e25721cc96c22262

Authored by Atsushi Nemoto
Committed by Linus Torvalds
1 parent 575c5807f6

rtc: make rtc_update_irq callable with irqs enabled

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>

Showing 6 changed files with 9 additions and 24 deletions Side-by-side Diff

drivers/rtc/interface.c
... ... @@ -371,19 +371,21 @@
371 371 * @rtc: the rtc device
372 372 * @num: how many irqs are being reported (usually one)
373 373 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
374   - * Context: in_interrupt(), irqs blocked
  374 + * Context: any
375 375 */
376 376 void rtc_update_irq(struct rtc_device *rtc,
377 377 unsigned long num, unsigned long events)
378 378 {
379   - spin_lock(&rtc->irq_lock);
  379 + unsigned long flags;
  380 +
  381 + spin_lock_irqsave(&rtc->irq_lock, flags);
380 382 rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
381   - spin_unlock(&rtc->irq_lock);
  383 + spin_unlock_irqrestore(&rtc->irq_lock, flags);
382 384  
383   - spin_lock(&rtc->irq_task_lock);
  385 + spin_lock_irqsave(&rtc->irq_task_lock, flags);
384 386 if (rtc->irq_task)
385 387 rtc->irq_task->func(rtc->irq_task->private_data);
386   - spin_unlock(&rtc->irq_task_lock);
  388 + spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
387 389  
388 390 wake_up_interruptible(&rtc->irq_queue);
389 391 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
drivers/rtc/rtc-dev.c
... ... @@ -60,8 +60,7 @@
60 60  
61 61 err = rtc_read_time(rtc, &tm);
62 62  
63   - local_irq_disable();
64   - spin_lock(&rtc->irq_lock);
  63 + spin_lock_irq(&rtc->irq_lock);
65 64 if (rtc->stop_uie_polling || err) {
66 65 rtc->uie_task_active = 0;
67 66 } else if (rtc->oldsecs != tm.tm_sec) {
68 67  
... ... @@ -74,10 +73,9 @@
74 73 } else if (schedule_work(&rtc->uie_task) == 0) {
75 74 rtc->uie_task_active = 0;
76 75 }
77   - spin_unlock(&rtc->irq_lock);
  76 + spin_unlock_irq(&rtc->irq_lock);
78 77 if (num)
79 78 rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF);
80   - local_irq_enable();
81 79 }
82 80 static void rtc_uie_timer(unsigned long data)
83 81 {
drivers/rtc/rtc-ds1305.c
... ... @@ -499,10 +499,7 @@
499 499 if (!test_bit(FLAG_EXITING, &ds1305->flags))
500 500 enable_irq(spi->irq);
501 501  
502   - /* rtc_update_irq() requires an IRQ-disabled context */
503   - local_irq_disable();
504 502 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
505   - local_irq_enable();
506 503 }
507 504  
508 505 /*
drivers/rtc/rtc-ds1307.c
... ... @@ -267,12 +267,7 @@
267 267 control &= ~DS1337_BIT_A1IE;
268 268 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control);
269 269  
270   - /* rtc_update_irq() assumes that it is called
271   - * from IRQ-disabled context.
272   - */
273   - local_irq_disable();
274 270 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
275   - local_irq_enable();
276 271 }
277 272  
278 273 out:
drivers/rtc/rtc-ds1374.c
... ... @@ -296,12 +296,7 @@
296 296 control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE);
297 297 i2c_smbus_write_byte_data(client, DS1374_REG_CR, control);
298 298  
299   - /* rtc_update_irq() assumes that it is called
300   - * from IRQ-disabled context.
301   - */
302   - local_irq_disable();
303 299 rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF);
304   - local_irq_enable();
305 300 }
306 301  
307 302 out:
drivers/rtc/rtc-test.c
... ... @@ -93,7 +93,6 @@
93 93 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
94 94  
95 95 retval = count;
96   - local_irq_disable();
97 96 if (strncmp(buf, "tick", 4) == 0)
98 97 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
99 98 else if (strncmp(buf, "alarm", 5) == 0)
... ... @@ -102,7 +101,6 @@
102 101 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
103 102 else
104 103 retval = -EINVAL;
105   - local_irq_enable();
106 104  
107 105 return retval;
108 106 }