wqueue: fix work_qcancel() judge error caused by the union in struct work_s

in struct work_s:
union
{
  struct
  {
    struct dq_entry_s dq; /* Implements a double linked list */
    clock_t qtime;        /* Time work queued */
  } s;
  struct wdog_s timer;    /* Delay expiry timer */
}

while we use WDOG_ISACTIVE(&work->timer) to decide use dq or timer,
that is error, wd_cancel() maybe modify this area, dq_rem() also can
modify this area.
So we can't use the WDOG_ISACTIVE(&work->timer) to take as the judgement,
when there is a union.

Fix:
swap the order in struct wdog_s, move the arg to the second 32bit

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-08-17 11:23:04 +08:00 committed by Petro Karashchenko
parent 4a87578bdb
commit 4bd88acf1b
1 changed files with 7 additions and 2 deletions

View File

@ -61,17 +61,22 @@ typedef uint32_t wdparm_t;
typedef CODE void (*wdentry_t)(wdparm_t arg); typedef CODE void (*wdentry_t)(wdparm_t arg);
/* This is the internal representation of the watchdog timer structure. */ /* This is the internal representation of the watchdog timer structure.
* Notice !!!
* Carefully with the struct wdog_s order, you may not directly modify
* this. This struct will combine in struct work_s in union type, and,
* wqueue will modify/check this struct in kwork work_qcancel().
*/
struct wdog_s struct wdog_s
{ {
FAR struct wdog_s *next; /* Support for singly linked lists. */ FAR struct wdog_s *next; /* Support for singly linked lists. */
wdparm_t arg; /* Callback argument */
wdentry_t func; /* Function to execute when delay expires */ wdentry_t func; /* Function to execute when delay expires */
#ifdef CONFIG_PIC #ifdef CONFIG_PIC
FAR void *picbase; /* PIC base address */ FAR void *picbase; /* PIC base address */
#endif #endif
sclock_t lag; /* Timer associated with the delay */ sclock_t lag; /* Timer associated with the delay */
wdparm_t arg; /* Callback argument */
}; };
/**************************************************************************** /****************************************************************************