You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/13 18:23:12 UTC
(nuttx) 29/30: arch/arm/src/common/stm32: keep timer state when lower-half init fails
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3043aab17e80e8f5045fb0acfab861cb27a292fc
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Oct 10 16:17:53 2026 +0200
arch/arm/src/common/stm32: keep timer state when lower-half init fails
stm32_timer_initialize() cleared the lower-half state and stored the
result of stm32_tim_init() before checking it. Initializing a timer that
is already in use returned -EINVAL but left an already registered timer
device with a NULL timer handle, which crashed on the next access.
Signed-off-by: raiden00pl <ra...@railab.me>
Assisted-by: Claude Code
---
arch/arm/src/common/stm32/stm32_tim_lowerhalf.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c b/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
index bec7708d1c0..7203cea6587 100644
--- a/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
+++ b/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
@@ -603,6 +603,7 @@ static void stm32_setcallback(struct timer_lowerhalf_s *lower,
int stm32_timer_initialize(const char *devpath, int timer)
{
struct stm32_lowerhalf_s *lower;
+ struct stm32_tim_dev_s *tim;
void *drvr;
tmrinfo("Init TIM%d\n", timer);
@@ -698,16 +699,17 @@ int stm32_timer_initialize(const char *devpath, int timer)
return -ENODEV;
}
+ tim = stm32_tim_init(timer);
+ if (tim == NULL)
+ {
+ return -EINVAL;
+ }
+
/* Initialize the elements of lower half state structure */
lower->started = false;
lower->callback = NULL;
- lower->tim = stm32_tim_init(timer);
-
- if (lower->tim == NULL)
- {
- return -EINVAL;
- }
+ lower->tim = tim;
/* Register the timer driver as /dev/timerX. The returned value from
* timer_register is a handle that could be used with timer_unregister().