]> git.droids-corp.org - dpdk.git/commitdiff
rib: mark error checks with unlikely
authorStephen Hemminger <stephen@networkplumber.org>
Wed, 13 Apr 2022 02:09:33 +0000 (19:09 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 1 Jun 2022 08:58:12 +0000 (10:58 +0200)
Also mark some conditional functions as const.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
lib/rib/rte_rib.c
lib/rib/rte_rib6.c

index 0603980cabd2e7ca3775b42fd4f98ea90893544e..f1fdddbbb44f56b90f2de51fc061639b18d53b84 100644 (file)
@@ -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;
 }
@@ -101,7 +101,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;
        }
@@ -149,7 +149,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;
        }
@@ -169,7 +169,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;
        }
@@ -246,7 +246,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;
        }
@@ -344,7 +344,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;
        }
@@ -355,7 +355,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;
        }
@@ -372,7 +372,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;
        }
@@ -383,7 +383,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;
        }
@@ -401,7 +401,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;
        }
@@ -436,7 +436,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;
@@ -446,7 +446,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;
index 042ac1f090bf57c12198862fbf50f0994a02b54d..650bf1b8f681a5e3d8adbfbc8c0d36d2207a07d8 100644 (file)
@@ -47,13 +47,13 @@ struct rte_rib6 {
 };
 
 static inline bool
-is_valid_node(struct rte_rib6_node *node)
+is_valid_node(const struct rte_rib6_node *node)
 {
        return (node->flag & RTE_RIB_VALID_NODE) == RTE_RIB_VALID_NODE;
 }
 
 static inline bool
-is_right_node(struct rte_rib6_node *node)
+is_right_node(const struct rte_rib6_node *node)
 {
        return node->parent->right == node;
 }
@@ -171,7 +171,7 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib,
        uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
        int i;
 
-       if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
+       if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
                rte_errno = EINVAL;
                return NULL;
        }
@@ -210,7 +210,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib,
        uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE];
        int i;
 
-       if ((rib == NULL) || (ip == NULL) || (depth > RIB6_MAXDEPTH)) {
+       if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) {
                rte_errno = EINVAL;
                return NULL;
        }
@@ -293,8 +293,7 @@ rte_rib6_insert(struct rte_rib6 *rib,
        int i, d;
        uint8_t common_depth, ip_xor;
 
-       if (unlikely((rib == NULL) || (ip == NULL) ||
-                       (depth > RIB6_MAXDEPTH))) {
+       if (unlikely((rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH))) {
                rte_errno = EINVAL;
                return NULL;
        }
@@ -413,7 +412,7 @@ int
 rte_rib6_get_ip(const struct rte_rib6_node *node,
                uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
 {
-       if ((node == NULL) || (ip == NULL)) {
+       if (unlikely(node == NULL || ip == NULL)) {
                rte_errno = EINVAL;
                return -1;
        }
@@ -424,7 +423,7 @@ rte_rib6_get_ip(const struct rte_rib6_node *node,
 int
 rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth)
 {
-       if ((node == NULL) || (depth == NULL)) {
+       if (unlikely(node == NULL || depth == NULL)) {
                rte_errno = EINVAL;
                return -1;
        }
@@ -441,7 +440,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node)
 int
 rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
 {
-       if ((node == NULL) || (nh == NULL)) {
+       if (unlikely(node == NULL || nh == NULL)) {
                rte_errno = EINVAL;
                return -1;
        }
@@ -452,7 +451,7 @@ rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
 int
 rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh)
 {
-       if (node == NULL) {
+       if (unlikely(node == NULL)) {
                rte_errno = EINVAL;
                return -1;
        }
@@ -471,7 +470,7 @@ rte_rib6_create(const char *name, int socket_id,
        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;
        }
@@ -506,7 +505,7 @@ rte_rib6_create(const char *name, int socket_id,
 
        /* allocate tailq entry */
        te = rte_zmalloc("RIB6_TAILQ_ENTRY", sizeof(*te), 0);
-       if (te == NULL) {
+       if (unlikely(te == NULL)) {
                RTE_LOG(ERR, LPM,
                        "Can not allocate tailq entry for RIB6 %s\n", name);
                rte_errno = ENOMEM;
@@ -516,7 +515,7 @@ rte_rib6_create(const char *name, int socket_id,
        /* Allocate memory to store the RIB6 data structures. */
        rib = rte_zmalloc_socket(mem_name,
                sizeof(struct rte_rib6), RTE_CACHE_LINE_SIZE, socket_id);
-       if (rib == NULL) {
+       if (unlikely(rib == NULL)) {
                RTE_LOG(ERR, LPM, "RIB6 %s memory allocation failed\n", name);
                rte_errno = ENOMEM;
                goto free_te;