This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 20ed760d4354997631972fcc82ee1cd51be08f67 Author: Darryl Ring <[email protected]> AuthorDate: Fri Oct 23 11:21:17 2026 -0700 drivers/timers/capture: Make getedges optional Not all capture drivers currently implement getedges which causes the CAPIOC_EDGES to assert and CAPIOC_ALL to dereference a null pointer. For CAPIOC_EDGES this will now return -ENOTTY instead of asserting. For CAPIOC_ALL this will fill in the duty cycle and frequency and leave the edges value at 0. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Darryl Ring <[email protected]> --- drivers/timers/capture.c | 20 +++++++++++++++++++- include/nuttx/timers/capture.h | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/timers/capture.c b/drivers/timers/capture.c index d632f788114..9a4ab2cc918 100644 --- a/drivers/timers/capture.c +++ b/drivers/timers/capture.c @@ -392,9 +392,17 @@ static int cap_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(ptr); + + /* Counting edges is optional for the lower half */ + + if (lower[0]->ops->getedges == NULL) + { + ret = -ENOTTY; + break; + } + for (i = 0; i < upper->nchan; i++) { - DEBUGASSERT(lower[i]->ops->getedges != NULL); ret = lower[i]->ops->getedges(lower[i], &ptr[i]); if (ret < 0) { @@ -428,6 +436,16 @@ static int cap_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; } + /* Counting edges is optional for the lower half, report zero + * edges if it is not supported. + */ + + if (lower[i]->ops->getedges == NULL) + { + ptr[i].edges = 0; + continue; + } + ret = lower[i]->ops->getedges(lower[i], &ptr[i].edges); if (ret < 0) { diff --git a/include/nuttx/timers/capture.h b/include/nuttx/timers/capture.h index 8ddc05dfe22..206999eabf4 100644 --- a/include/nuttx/timers/capture.h +++ b/include/nuttx/timers/capture.h @@ -199,7 +199,7 @@ struct cap_ops_s CODE int (*getfreq)(FAR struct cap_lowerhalf_s *lower, FAR uint32_t *freq); - /* Get the result pwm capture edges value */ + /* Get the result pwm capture edges value (optional) */ CODE int (*getedges)(FAR struct cap_lowerhalf_s *lower, FAR uint32_t *edges);
