CV-Bowen opened a new pull request, #22067:
URL: https://github.com/apache/nuttx/pull/22067
## Summary
Two fixes in the watchdog upper half, plus the list helper the second one
needs.
- `drivers/timers/watchdog: print the status with unsigned formats`:
`struct watchdog_status_s` holds `timeout` and `timeleft` as `uint32_t`,
but `wdog_read()` printed them with `PRId32`, so any timeout of 2^31 ms
or more read back negative.
- `drivers/timers/watchdog: detach the channels under the lock on
unregister`: `watchdog_unregister()` freed the supervision channels from
the list while a keepalive trigger running in interrupt context, or on
another cpu, could still be walking it in
`watchdog_channel_expired()`. The list is now detached under
`upper->slock` and the channels freed outside of it.
- `list: add list_move support`: the helper the detach uses. It moves all
entries from one list to another and leaves the source empty.
## Impact
- The watchdog status text now shows the timeout and timeleft as unsigned
numbers, matching the field type.
- `watchdog_unregister()` no longer frees a channel a concurrent trigger can
still reach; the list is empty by the time the channels are freed.
- One new macro in `include/nuttx/list.h`; no existing caller changes.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64; sim: gcc 13.1.0
`sim:watchdog` (`CONFIG_WATCHDOG_WDOG=y`), which exposes `/dev/watchdog0`
and lets the status text be read back with `read()`:
| tree | `read()` of `/dev/watchdog0` after `WDIOC_SETTIMEOUT` 3000000000 ms
|
|---|---|
| master | `timeout : -1294967296`, `timeleft : -1294967296` |
| this PR | `timeout : 3000000000`, `timeleft : 3000000000` |
3000000000 does not fit in `int32_t`, so the old `PRId32` printed it as
`-1294967296`.
The unregister fix closes a race between `watchdog_unregister()` freeing the
channels and a keepalive trigger walking them in interrupt context. It
cannot be reproduced deterministically on `sim`, so the check there is the
status path above plus the `sim:watchdog` build (0 warnings) and the rpmsg
baseline; the race itself is argued from the lock, not observed.
<details><summary>Test program (not part of this PR)</summary>
```c
/* Probe: run through the watchdog status text path itself - set a timeout
* whose millisecond value exceeds INT32_MAX, then read() /dev/watchdog0,
* which formats it with wdog_read().
*/
#include <nuttx/config.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <nuttx/timers/watchdog.h>
int main(int argc, FAR char *argv[])
{
char buf[256];
ssize_t n;
int fd = open("/dev/watchdog0", O_RDONLY);
if (fd < 0)
{
printf("open failed\n");
return 1;
}
if (ioctl(fd, WDIOC_SETTIMEOUT, 3000000000ul) < 0 ||
ioctl(fd, WDIOC_START, 0) < 0)
{
printf("SETTIMEOUT/START failed\n");
return 1;
}
memset(buf, 0, sizeof(buf));
n = read(fd, buf, sizeof(buf) - 1);
if (n < 0)
{
printf("read failed\n");
return 1;
}
printf("--- status text ---\n%s--- end ---\n", buf);
ioctl(fd, WDIOC_STOP, 0);
close(fd);
return 0;
}
```
</details>
<details><summary>master</summary>
```
--- status text ---
Status :
flags : 0x00000003
timeout : -1294967296
timeleft : -1294967296
--- end ---
```
</details>
<details><summary>this PR</summary>
```
--- status text ---
Status :
flags : 0x00000003
timeout : 3000000000
timeleft : 3000000000
--- end ---
```
</details>
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC
disabled, which current master needs for nxinit to start nsh there; unrelated
to this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]