aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Elo <matias.elo@nokia.com>2023-05-05 17:05:17 +0300
committerMatias Elo <matias.elo@nokia.com>2023-05-09 10:17:39 +0300
commit13918e69c848509cd8b75eb069ec53e4f8f24f74 (patch)
tree3d297d005be3646e6514b164478a7f44e1e69016
parent1aaf5cf55a0ca0154cd4d7ff9fb7bc985eaa136a (diff)
linux-gen: timer: fix odp_timeout_fresh() crash
Fix crash when calling odp_timeout_fresh() with a timeout event which has not yet been attached to a timer. Also, make sure that newly allocated timeouts are not attached to the previous timer. Signed-off-by: Matias Elo <matias.elo@nokia.com> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
-rw-r--r--platform/linux-generic/odp_timer.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index 18e1a7e23..b2ed7f102 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -1755,6 +1755,11 @@ int odp_timeout_fresh(odp_timeout_t tmo)
{
const odp_timeout_hdr_t *hdr = timeout_hdr(tmo);
odp_timer_t hdl = hdr->timer;
+
+ /* Timeout not connected to a timer */
+ if (odp_unlikely(hdl == ODP_TIMER_INVALID))
+ return 0;
+
timer_pool_t *tp = handle_to_tp(hdl);
uint32_t idx = handle_to_idx(hdl, tp);
tick_buf_t *tb = &tp->tick_buf[idx];
@@ -1767,6 +1772,7 @@ int odp_timeout_fresh(odp_timeout_t tmo)
odp_timeout_t odp_timeout_alloc(odp_pool_t pool_hdl)
{
+ odp_timeout_hdr_t *hdr;
odp_event_t event;
pool_t *pool;
@@ -1780,6 +1786,9 @@ odp_timeout_t odp_timeout_alloc(odp_pool_t pool_hdl)
if (odp_unlikely(event == ODP_EVENT_INVALID))
return ODP_TIMEOUT_INVALID;
+ hdr = timeout_hdr_from_event(event);
+ hdr->timer = ODP_TIMER_INVALID;
+
return odp_timeout_from_event(event);
}