Skip to content

Commit d691eb9

Browse files
Alessandro ZummoLinus Torvalds
authored andcommitted
RTC: periodic irq fix
Add kernel/kernel and kernel/user locking for the periodic irq feature of the rtc class. PIE ioctls are also supported. Signed-off-by: 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>
1 parent 16a72c4 commit d691eb9

3 files changed

Lines changed: 24 additions & 25 deletions

File tree

‎drivers/rtc/class.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
153153
mutex_init(&rtc->ops_lock);
154154
spin_lock_init(&rtc->irq_lock);
155155
spin_lock_init(&rtc->irq_task_lock);
156+
init_waitqueue_head(&rtc->irq_queue);
156157

157158
strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
158159
snprintf(rtc->dev.bus_id, BUS_ID_SIZE, "rtc%d", id);

‎drivers/rtc/interface.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,25 @@ int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
210210
if (task == NULL || task->func == NULL)
211211
return -EINVAL;
212212

213+
/* Cannot register while the char dev is in use */
214+
if (!(mutex_trylock(&rtc->char_lock)))
215+
return -EBUSY;
216+
213217
spin_lock_irq(&rtc->irq_task_lock);
214218
if (rtc->irq_task == NULL) {
215219
rtc->irq_task = task;
216220
retval = 0;
217221
}
218222
spin_unlock_irq(&rtc->irq_task_lock);
219223

224+
mutex_unlock(&rtc->char_lock);
225+
220226
return retval;
221227
}
222228
EXPORT_SYMBOL_GPL(rtc_irq_register);
223229

224230
void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task)
225231
{
226-
227232
spin_lock_irq(&rtc->irq_task_lock);
228233
if (rtc->irq_task == task)
229234
rtc->irq_task = NULL;
@@ -240,8 +245,10 @@ int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled
240245
return -ENXIO;
241246

242247
spin_lock_irqsave(&rtc->irq_task_lock, flags);
248+
if (rtc->irq_task != NULL && task == NULL)
249+
err = -EBUSY;
243250
if (rtc->irq_task != task)
244-
err = -ENXIO;
251+
err = -EACCES;
245252
spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
246253

247254
if (err == 0)
@@ -260,8 +267,10 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
260267
return -ENXIO;
261268

262269
spin_lock_irqsave(&rtc->irq_task_lock, flags);
270+
if (rtc->irq_task != NULL && task == NULL)
271+
err = -EBUSY;
263272
if (rtc->irq_task != task)
264-
err = -ENXIO;
273+
err = -EACCES;
265274
spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
266275

267276
if (err == 0) {

‎drivers/rtc/rtc-dev.c‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,6 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
238238
break;
239239
}
240240

241-
/* avoid conflicting IRQ users */
242-
if (cmd == RTC_PIE_ON || cmd == RTC_PIE_OFF || cmd == RTC_IRQP_SET) {
243-
spin_lock_irq(&rtc->irq_task_lock);
244-
if (rtc->irq_task)
245-
err = -EBUSY;
246-
spin_unlock_irq(&rtc->irq_task_lock);
247-
248-
if (err < 0)
249-
return err;
250-
}
251-
252241
/* try the driver's ioctl interface */
253242
if (ops->ioctl) {
254243
err = ops->ioctl(rtc->dev.parent, cmd, arg);
@@ -338,18 +327,20 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
338327
err = rtc_set_time(rtc, &tm);
339328
break;
340329

341-
case RTC_IRQP_READ:
342-
if (ops->irq_set_freq)
343-
err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
344-
else
345-
err = -ENOTTY;
330+
case RTC_PIE_ON:
331+
err = rtc_irq_set_state(rtc, NULL, 1);
332+
break;
333+
334+
case RTC_PIE_OFF:
335+
err = rtc_irq_set_state(rtc, NULL, 0);
346336
break;
347337

348338
case RTC_IRQP_SET:
349-
if (ops->irq_set_freq)
350-
err = rtc_irq_set_freq(rtc, rtc->irq_task, arg);
351-
else
352-
err = -ENOTTY;
339+
err = rtc_irq_set_freq(rtc, NULL, arg);
340+
break;
341+
342+
case RTC_IRQP_READ:
343+
err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
353344
break;
354345

355346
#if 0
@@ -449,8 +440,6 @@ void rtc_dev_prepare(struct rtc_device *rtc)
449440
rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
450441

451442
mutex_init(&rtc->char_lock);
452-
spin_lock_init(&rtc->irq_lock);
453-
init_waitqueue_head(&rtc->irq_queue);
454443
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
455444
INIT_WORK(&rtc->uie_task, rtc_uie_task);
456445
setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc);

0 commit comments

Comments
 (0)