You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/01/08 03:56:25 UTC
(nuttx) 01/02: drivers/timers: Remove redundant check for crefs > 0 before decrement
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit bc35ea17d21dea52ac2bba99de361ed48a845aac
Author: fangpeina <fa...@xiaomi.com>
AuthorDate: Wed Jul 23 21:38:41 2025 +0800
drivers/timers: Remove redundant check for crefs > 0 before decrement
The reference count (upper->crefs) is incremented in timer_open()
only after ensuring it will not overflow, timer_close() is only
called after a successful open. Therefore, crefs should never be
zero when timer_close() is called. The check for crefs > 0 before
decrementing is unnecessary and has been removed to simplify the code.
Signed-off-by: fangpeina <fa...@xiaomi.com>
---
drivers/timers/timer.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/timers/timer.c b/drivers/timers/timer.c
index 582cad27480..365c5099d9a 100644
--- a/drivers/timers/timer.c
+++ b/drivers/timers/timer.c
@@ -206,15 +206,7 @@ static int timer_close(FAR struct file *filep)
return ret;
}
- /* Decrement the references to the driver. If the reference count will
- * decrement to 0, then uninitialize the driver.
- */
-
- if (upper->crefs > 0)
- {
- upper->crefs--;
- }
-
+ upper->crefs--;
nxmutex_unlock(&upper->lock);
return OK;
}