Skip to content

Commit 1c6b39a

Browse files
alarmtimers: Return -ENOTSUPP if no RTC device is present
Toralf Förster and Richard Weinberger noted that if there is no RTC device, the alarm timers core prints out an annoying "ALARM timers will not wake from suspend" message. This warning has been removed in a previous patch, however the issue still remains: The original idea was to support alarm timers even if there was no rtc device, as long as the system didn't go into suspend. However, after further consideration, communicating to the application that alarmtimers are not fully functional seems like the better solution. So this patch makes it so we return -ENOTSUPP to any posix _ALARM clockid calls if there is no backing RTC device on the system. Further this changes the behavior where when there is no rtc device we will check for one on clock_getres, clock_gettime, timer_create, and timer_nsleep instead of on suspend. CC: Toralf Förster <[email protected]> CC: Richard Weinberger <[email protected] CC: Peter Zijlstra <[email protected]> CC: Thomas Gleixner <[email protected]> Reported-by: Toralf Förster <[email protected]> Reported by: Richard Weinberger <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent c008ba5 commit 1c6b39a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

kernel/time/alarmtimer.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ static struct rtc_device *alarmtimer_get_rtcdev(void)
107107

108108
return ret;
109109
}
110+
#else
111+
#define alarmtimer_get_rtcdev() (0)
112+
#define rtcdev (0)
110113
#endif
111114

112115

@@ -231,7 +234,7 @@ static int alarmtimer_suspend(struct device *dev)
231234
freezer_delta = ktime_set(0, 0);
232235
spin_unlock_irqrestore(&freezer_delta_lock, flags);
233236

234-
rtc = alarmtimer_get_rtcdev();
237+
rtc = rtcdev;
235238
/* If we have no rtcdev, just return */
236239
if (!rtc)
237240
return 0;
@@ -381,6 +384,9 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
381384
{
382385
clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid;
383386

387+
if (!alarmtimer_get_rtcdev())
388+
return -ENOTSUPP;
389+
384390
return hrtimer_get_res(baseid, tp);
385391
}
386392

@@ -395,6 +401,9 @@ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
395401
{
396402
struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
397403

404+
if (!alarmtimer_get_rtcdev())
405+
return -ENOTSUPP;
406+
398407
*tp = ktime_to_timespec(base->gettime());
399408
return 0;
400409
}
@@ -410,6 +419,9 @@ static int alarm_timer_create(struct k_itimer *new_timer)
410419
enum alarmtimer_type type;
411420
struct alarm_base *base;
412421

422+
if (!alarmtimer_get_rtcdev())
423+
return -ENOTSUPP;
424+
413425
if (!capable(CAP_WAKE_ALARM))
414426
return -EPERM;
415427

@@ -444,6 +456,9 @@ static void alarm_timer_get(struct k_itimer *timr,
444456
*/
445457
static int alarm_timer_del(struct k_itimer *timr)
446458
{
459+
if (!rtcdev)
460+
return -ENOTSUPP;
461+
447462
alarm_cancel(&timr->it.alarmtimer);
448463
return 0;
449464
}
@@ -461,6 +476,9 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
461476
struct itimerspec *new_setting,
462477
struct itimerspec *old_setting)
463478
{
479+
if (!rtcdev)
480+
return -ENOTSUPP;
481+
464482
/* Save old values */
465483
old_setting->it_interval =
466484
ktime_to_timespec(timr->it.alarmtimer.period);
@@ -600,6 +618,9 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
600618
int ret = 0;
601619
struct restart_block *restart;
602620

621+
if (!alarmtimer_get_rtcdev())
622+
return -ENOTSUPP;
623+
603624
if (!capable(CAP_WAKE_ALARM))
604625
return -EPERM;
605626

0 commit comments

Comments
 (0)