sched/wdog/wd_start.c: prevent accessing watch-dog lag if head is NULL

If statement in line 103 could acces wdactivelist.head->lag when head was
NULL which could result in hard fault. The statement was also redundant
as the same condition is checked in the while loop below. This change
remove the if statement to prevent hard fault to occur.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2021-09-03 09:37:43 +02:00 committed by David Sidrane
parent df088c39f0
commit cdfe7b5a54

View File

@ -98,40 +98,35 @@ static inline void wd_expiration(void)
FAR struct wdog_s *wdog;
wdentry_t func;
/* Check if the watchdog at the head of the list is ready to run */
/* Process the watchdog at the head of the list as well as any
* other watchdogs that became ready to run at this time
*/
if (((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0)
while (g_wdactivelist.head &&
((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0)
{
/* Process the watchdog at the head of the list as well as any
* other watchdogs that became ready to run at this time
/* Remove the watchdog from the head of the list */
wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdactivelist);
/* If there is another watchdog behind this one, update its
* its lag (this shouldn't be necessary).
*/
while (g_wdactivelist.head &&
((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0)
if (g_wdactivelist.head)
{
/* Remove the watchdog from the head of the list */
wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdactivelist);
/* If there is another watchdog behind this one, update its
* its lag (this shouldn't be necessary).
*/
if (g_wdactivelist.head)
{
((FAR struct wdog_s *)g_wdactivelist.head)->lag += wdog->lag;
}
/* Indicate that the watchdog is no longer active. */
func = wdog->func;
wdog->func = NULL;
/* Execute the watchdog function */
up_setpicbase(wdog->picbase);
CALL_FUNC(func, wdog->arg);
((FAR struct wdog_s *)g_wdactivelist.head)->lag += wdog->lag;
}
/* Indicate that the watchdog is no longer active. */
func = wdog->func;
wdog->func = NULL;
/* Execute the watchdog function */
up_setpicbase(wdog->picbase);
CALL_FUNC(func, wdog->arg);
}
}