From patchwork Fri May 27 16:25:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 68775 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp182576qge; Fri, 27 May 2016 09:26:15 -0700 (PDT) X-Received: by 10.200.38.154 with SMTP id 26mr14732596qto.44.1464366375189; Fri, 27 May 2016 09:26:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 22si18203302qkf.45.2016.05.27.09.26.14; Fri, 27 May 2016 09:26:15 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 93580617B3; Fri, 27 May 2016 16:26:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E732561751; Fri, 27 May 2016 16:26:08 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id CF8E061758; Fri, 27 May 2016 16:26:07 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id CBEB56174F for ; Fri, 27 May 2016 16:26:06 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id k98so48173303lfi.1 for ; Fri, 27 May 2016 09:26:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ghpi543qSA8R1Aw2sSJ8R0FnHTHDCdh02vpPiv1zgEY=; b=ig0FNDALOVBgy0jjeYNB8VRDSbSQz0deQrpR6T4FrIXu/VWKUYzkR7X8aNISlrNqbj fkVV/6vfJT4qCidzQXfj+z2A1E/+mot5zu9GmGpVM47eOZCrHBxNmXegfXxLlvo+69hE aWEsDyDHoeYYxwWBJkTkhH3Pbp4CgVeO89pGeZOmD9O6hrVlPn48jBG7f72Mj9NUI1D2 0jCEtQI+wJNKooj6+SVRrVpE87eUTO7U5Tzyu3MmAfckSQtziS1du/7EPaeJlvnIuBBz KhazTyRLLZKA4LgzSiyBjOLXAXmji1Shru0qzG2h4FX1dqG4q5pBt4wB9vcYgriUFkSD PjWA== X-Gm-Message-State: ALyK8tLDT+N42EMyXFOxkBhv0uwQif6fl+ogKj+vpoA+Zz90waihYRwrKga3pM+bfmz5qpsq+ww= X-Received: by 10.25.149.84 with SMTP id x81mr3951926lfd.166.1464366364663; Fri, 27 May 2016 09:26:04 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id u11sm619442lja.16.2016.05.27.09.26.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 09:26:03 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 27 May 2016 19:25:10 +0300 Message-Id: <1464366310-5066-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: timers patch Subject: [lng-odp] [PATCHv2] linux-generic: timer fix odp_timer_pool_create return code X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Accodring to API return code for fail case is ODP_TIMER_POOL_INVALID and errno set event if it's defined to NULL. Also add check on pool alloc that input parameter is not invalid. https://bugs.linaro.org/show_bug.cgi?id=2139 Signed-off-by: Maxim Uvarov --- v2: 1. ODP_ABORT - > ODP_ERR 2. simplify return code (Bill, Ola) platform/linux-generic/odp_timer.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 4e56fb0..996edf0 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -221,16 +221,15 @@ 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 *odp_timer_pool_new( - const char *_name, - const odp_timer_pool_param_t *param) +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); if (odp_unlikely(tp_idx >= MAX_TIMER_POOLS)) { /* Restore the previous value */ odp_atomic_sub_u32(&num_timer_pools, 1); __odp_errno = ENFILE; /* Table overflow */ - return NULL; + return ODP_TIMER_POOL_INVALID; } size_t sz0 = ODP_ALIGN_ROUNDUP(sizeof(odp_timer_pool), ODP_CACHE_LINE_SIZE); @@ -794,10 +793,9 @@ odp_timer_pool_create(const char *name, /* Verify that we have a valid (non-zero) timer resolution */ if (param->res_ns == 0) { __odp_errno = EINVAL; - return NULL; + return ODP_TIMER_POOL_INVALID; } - odp_timer_pool_t tp = odp_timer_pool_new(name, param); - return tp; + return odp_timer_pool_new(name, param); } void odp_timer_pool_start(void) @@ -845,17 +843,18 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid, odp_queue_t queue, void *user_ptr) { - if (odp_unlikely(queue == ODP_QUEUE_INVALID)) - ODP_ABORT("%s: Invalid queue handle\n", tpid->name); + if (odp_unlikely(tpid == ODP_TIMER_POOL_INVALID)) { + ODP_ERR("Invalid timer pool.\n"); + return ODP_TIMER_INVALID; + } + + if (odp_unlikely(queue == ODP_QUEUE_INVALID)) { + ODP_ERR("%s: Invalid queue handle\n", tpid->name); + return ODP_TIMER_INVALID; + } /* We don't care about the validity of user_ptr because we will not * attempt to dereference it */ - odp_timer_t hdl = timer_alloc(tpid, queue, user_ptr); - if (odp_likely(hdl != ODP_TIMER_INVALID)) { - /* Success */ - return hdl; - } - /* errno set by timer_alloc() */ - return ODP_TIMER_INVALID; + return timer_alloc(tpid, queue, user_ptr); } odp_event_t odp_timer_free(odp_timer_t hdl)