Skip to content

Commit

Permalink
RTC: Prevents a division by zero in kernel code.
Browse files Browse the repository at this point in the history
This patch prevents a user space program from calling the RTC_IRQP_SET
ioctl with a negative value of frequency. Also, if this call is make
with a zero value of frequency, there would be a division by zero in the
kernel code.

[jstultz: Also initialize irq_freq to 1 to catch other divbyzero issues]

CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
Signed-off-by: John Stultz <john.stultz@linaro.org>
  • Loading branch information
Marcelo Roberto Jimenez authored and John Stultz committed Feb 3, 2011
1 parent 9118626 commit 83a06bf
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/rtc/class.c
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
rtc->id = id;
rtc->ops = ops;
rtc->owner = owner;
rtc->irq_freq = 1;
rtc->max_user_freq = 64;
rtc->dev.parent = dev;
rtc->dev.class = rtc_class;
3 changes: 3 additions & 0 deletions drivers/rtc/interface.c
Original file line number Diff line number Diff line change
@@ -464,6 +464,9 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
int err = 0;
unsigned long flags;

if (freq <= 0)
return -EINVAL;

spin_lock_irqsave(&rtc->irq_task_lock, flags);
if (rtc->irq_task != NULL && task == NULL)
err = -EBUSY;

0 comments on commit 83a06bf

Please sign in to comment.