From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E3F90A04FF; Wed, 13 Apr 2022 04:09:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E5634410E1; Wed, 13 Apr 2022 04:09:41 +0200 (CEST) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id DA60D40683 for ; Wed, 13 Apr 2022 04:09:39 +0200 (CEST) Received: by mail-pj1-f53.google.com with SMTP id ll10so535357pjb.5 for ; Tue, 12 Apr 2022 19:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nHgAHsbNbP+KZy+Skj9h08/u+Ay3SEum6MlNzcL1J/w=; b=H9WzpbTc7/QqCwViIK1DKt6N0mWHBPw1OEaDbNQ49g5XRclYs5qQ4ksJ+nrQMco2S6 TvUiNQOB2a8X2PkTXEssRYpbIlcVPhiTm/XyLvo5qATJ64GcQgrfjyWx4tFr144AP7Tf t0HPrtpvbXtQb6saoNvTjV3Bki97D5r30dzGoFsZwWvdJq7JWuPfMCzPTzTCO4VZgkDf 8mMDevEXEG3rtit9832V/bTP6sHR33gjZ0KvoxyvGwld4N7gM2Gi+c0MTCDIJk9ThAwb t9tVgGWpO7EYsW+jTX2z2iuj3F1QP7jxw11sW+FjJiu4a3I0TmDCAN8F4O24ILeEC1KB /IlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nHgAHsbNbP+KZy+Skj9h08/u+Ay3SEum6MlNzcL1J/w=; b=SvMXp1OpDJVQhNaOaENDK14Ot8fB8V2gA2wnOJbM09IfH6nfU23OdlBGB4eQql8ShW Ae0P2hFsIViDyXXWOaGgEWF3OYXrhmdSJRjAuHFSqNOpNKD2eAwE/04ZKQMb4a4eFnPD /0VrOM7Ma7vLTElYGy/igXsNa9gKMlRlk3pbx4DgJXBCrQZXClQm5zZI9yEXuGgLTPCg 9/VEi3euyU3GTtZq+qGo1MjpkZXShO5yujMh98fZJddMJkZpE5CN36MUzHhBbROmrnqf C44MUlzBKWpsDAScx+cdsCzd/wQELohXfZA/BZiAFUG7tMtFrMmzhaQkf+6ZCFieNIc3 dXrA== X-Gm-Message-State: AOAM533sA8073/wRWaic3edJwVHbJxwojk6f1mMsh3MmLJwhiF2x8onU 42tukbvvRPJ1jvnGbuO5KZES50ZRJbSwqg== X-Google-Smtp-Source: ABdhPJx39oSFz+D/xk4umJEV6NFXn1KRKq463VPkFbMC/6jbwzPC71uiGks/nL20+RNBQQVYp0m3RQ== X-Received: by 2002:a17:90a:9204:b0:1ca:8698:2470 with SMTP id m4-20020a17090a920400b001ca86982470mr8251004pjo.199.1649815778817; Tue, 12 Apr 2022 19:09:38 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id pg14-20020a17090b1e0e00b001c75634df70sm802553pjb.31.2022.04.12.19.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 19:09:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Vladimir Medvedkin Subject: [PATCH 1/2] rib: mark error checks with unlikely Date: Tue, 12 Apr 2022 19:09:33 -0700 Message-Id: <20220413020935.90499-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413020935.90499-1-stephen@networkplumber.org> References: <20220413020935.90499-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Also mark some conditional functions as const. Signed-off-by: Stephen Hemminger --- lib/rib/rte_rib.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/rib/rte_rib.c b/lib/rib/rte_rib.c index cd9e823068d2..2a3de5065a31 100644 --- a/lib/rib/rte_rib.c +++ b/lib/rib/rte_rib.c @@ -48,13 +48,13 @@ struct rte_rib { }; static inline bool -is_valid_node(struct rte_rib_node *node) +is_valid_node(const struct rte_rib_node *node) { return (node->flag & RTE_RIB_VALID_NODE) == RTE_RIB_VALID_NODE; } static inline bool -is_right_node(struct rte_rib_node *node) +is_right_node(const struct rte_rib_node *node) { return node->parent->right == node; } @@ -99,7 +99,7 @@ rte_rib_lookup(struct rte_rib *rib, uint32_t ip) { struct rte_rib_node *cur, *prev = NULL; - if (rib == NULL) { + if (unlikely(rib == NULL)) { rte_errno = EINVAL; return NULL; } @@ -147,7 +147,7 @@ __rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth) struct rte_rib_node * rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth) { - if ((rib == NULL) || (depth > RIB_MAXDEPTH)) { + if (unlikely(rib == NULL || depth > RIB_MAXDEPTH)) { rte_errno = EINVAL; return NULL; } @@ -167,7 +167,7 @@ rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, { struct rte_rib_node *tmp, *prev = NULL; - if ((rib == NULL) || (depth > RIB_MAXDEPTH)) { + if (unlikely(rib == NULL || depth > RIB_MAXDEPTH)) { rte_errno = EINVAL; return NULL; } @@ -244,7 +244,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth) uint32_t common_prefix; uint8_t common_depth; - if ((rib == NULL) || (depth > RIB_MAXDEPTH)) { + if (unlikely(rib == NULL || depth > RIB_MAXDEPTH)) { rte_errno = EINVAL; return NULL; } @@ -342,7 +342,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth) int rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip) { - if ((node == NULL) || (ip == NULL)) { + if (unlikely(node == NULL || ip == NULL)) { rte_errno = EINVAL; return -1; } @@ -353,7 +353,7 @@ rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip) int rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth) { - if ((node == NULL) || (depth == NULL)) { + if (unlikely(node == NULL || depth == NULL)) { rte_errno = EINVAL; return -1; } @@ -370,7 +370,7 @@ rte_rib_get_ext(struct rte_rib_node *node) int rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh) { - if ((node == NULL) || (nh == NULL)) { + if (unlikely(node == NULL || nh == NULL)) { rte_errno = EINVAL; return -1; } @@ -381,7 +381,7 @@ rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh) int rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh) { - if (node == NULL) { + if (unlikely(node == NULL)) { rte_errno = EINVAL; return -1; } @@ -399,7 +399,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf) struct rte_mempool *node_pool; /* Check user arguments. */ - if (name == NULL || conf == NULL || conf->max_nodes <= 0) { + if (unlikely(name == NULL || conf == NULL || conf->max_nodes <= 0)) { rte_errno = EINVAL; return NULL; } @@ -434,7 +434,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf) /* allocate tailq entry */ te = rte_zmalloc("RIB_TAILQ_ENTRY", sizeof(*te), 0); - if (te == NULL) { + if (unlikely(te == NULL)) { RTE_LOG(ERR, LPM, "Can not allocate tailq entry for RIB %s\n", name); rte_errno = ENOMEM; @@ -444,7 +444,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf) /* Allocate memory to store the RIB data structures. */ rib = rte_zmalloc_socket(mem_name, sizeof(struct rte_rib), RTE_CACHE_LINE_SIZE, socket_id); - if (rib == NULL) { + if (unlikely(rib == NULL)) { RTE_LOG(ERR, LPM, "RIB %s memory allocation failed\n", name); rte_errno = ENOMEM; goto free_te; -- 2.35.1