diff mbox

[API-NEXT,5/5] linux-gen: timer: fix creating timer pool with no name

Message ID 1476434952-8282-6-git-send-email-matias.elo@nokia.com
State Accepted
Commit d9615289bf6f60bd3a04f8138d5b487efda96a49
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) Oct. 14, 2016, 8:49 a.m. UTC
Previously trying to create a timer pool with no name (=NULL) caused a
segfault.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 platform/linux-generic/odp_timer.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index becea9d..22b7205 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -222,7 +222,7 @@  static inline odp_timer_t tp_idx_to_handle(struct odp_timer_pool_s *tp,
 static void itimer_init(odp_timer_pool *tp);
 static void itimer_fini(odp_timer_pool *tp);
 
-static odp_timer_pool_t odp_timer_pool_new(const char *_name,
+static odp_timer_pool_t odp_timer_pool_new(const char *name,
 					   const odp_timer_pool_param_t *param)
 {
 	uint32_t tp_idx = odp_atomic_fetch_add_u32(&num_timer_pools, 1);
@@ -238,14 +238,20 @@  static odp_timer_pool_t odp_timer_pool_new(const char *_name,
 			ODP_CACHE_LINE_SIZE);
 	size_t sz2 = ODP_ALIGN_ROUNDUP(sizeof(odp_timer) * param->num_timers,
 			ODP_CACHE_LINE_SIZE);
-	odp_shm_t shm = odp_shm_reserve(_name, sz0 + sz1 + sz2,
+	odp_shm_t shm = odp_shm_reserve(name, sz0 + sz1 + sz2,
 			ODP_CACHE_LINE_SIZE, ODP_SHM_SW_ONLY);
 	if (odp_unlikely(shm == ODP_SHM_INVALID))
 		ODP_ABORT("%s: timer pool shm-alloc(%zuKB) failed\n",
-			  _name, (sz0 + sz1 + sz2) / 1024);
+			  name, (sz0 + sz1 + sz2) / 1024);
 	odp_timer_pool *tp = (odp_timer_pool *)odp_shm_addr(shm);
 	odp_atomic_init_u64(&tp->cur_tick, 0);
-	snprintf(tp->name, sizeof(tp->name), "%s", _name);
+
+	if (name == NULL) {
+		tp->name[0] = 0;
+	} else {
+		strncpy(tp->name, name, ODP_TIMER_POOL_NAME_LEN - 1);
+		tp->name[ODP_TIMER_POOL_NAME_LEN - 1] = 0;
+	}
 	tp->shm = shm;
 	tp->param = *param;
 	tp->min_rel_tck = odp_timer_ns_to_tick(tp, param->min_tmo);