]> www.infradead.org Git - users/hch/misc.git/commitdiff
tipc: adjust tipc_nodeid2string() to return string length
authorDmitry Antipov <dmantipov@yandex.ru>
Fri, 26 Sep 2025 07:41:13 +0000 (10:41 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 30 Sep 2025 09:22:39 +0000 (11:22 +0200)
Since the value returned by 'tipc_nodeid2string()' is not used, the
function may be adjusted to return the length of the result, which
is helpful to drop a few calls to 'strlen()' in 'tipc_link_create()'
and 'tipc_link_bc_create()'. Compile tested only.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250926074113.914399-1-dmantipov@yandex.ru
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/tipc/addr.c
net/tipc/addr.h
net/tipc/link.c

index fd0796269eed176fa7ad413727c0cd3bfa8440ac..6f5c54cbf8d9956dae3f2b11b43825cc96f2d629 100644 (file)
@@ -79,7 +79,7 @@ void tipc_set_node_addr(struct net *net, u32 addr)
        pr_info("Node number set to %u\n", addr);
 }
 
-char *tipc_nodeid2string(char *str, u8 *id)
+int tipc_nodeid2string(char *str, u8 *id)
 {
        int i;
        u8 c;
@@ -109,7 +109,7 @@ char *tipc_nodeid2string(char *str, u8 *id)
        if (i == NODE_ID_LEN) {
                memcpy(str, id, NODE_ID_LEN);
                str[NODE_ID_LEN] = 0;
-               return str;
+               return i;
        }
 
        /* Translate to hex string */
@@ -120,5 +120,5 @@ char *tipc_nodeid2string(char *str, u8 *id)
        for (i = NODE_ID_STR_LEN - 2; str[i] == '0'; i--)
                str[i] = 0;
 
-       return str;
+       return i + 1;
 }
index 93f82398283d8986b5a75f7edc2a3d5e40b98067..a113cf7e1f89f4248f8c36a7d79b5f62ccb4596e 100644 (file)
@@ -130,6 +130,6 @@ static inline int in_own_node(struct net *net, u32 addr)
 bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
 void tipc_set_node_id(struct net *net, u8 *id);
 void tipc_set_node_addr(struct net *net, u32 addr);
-char *tipc_nodeid2string(char *str, u8 *id);
+int tipc_nodeid2string(char *str, u8 *id);
 
 #endif
index 3ee44d73170041d7cb470bf625956b867b25bae5..931f55f781a133573f2f5e504139dab974a22358 100644 (file)
@@ -495,11 +495,9 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
 
        /* Set link name for unicast links only */
        if (peer_id) {
-               tipc_nodeid2string(self_str, tipc_own_id(net));
-               if (strlen(self_str) > 16)
+               if (tipc_nodeid2string(self_str, tipc_own_id(net)) > NODE_ID_LEN)
                        sprintf(self_str, "%x", self);
-               tipc_nodeid2string(peer_str, peer_id);
-               if (strlen(peer_str) > 16)
+               if (tipc_nodeid2string(peer_str, peer_id) > NODE_ID_LEN)
                        sprintf(peer_str, "%x", peer);
        }
        /* Peer i/f name will be completed by reset/activate message */
@@ -570,8 +568,7 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer, u8 *peer_id,
        if (peer_id) {
                char peer_str[NODE_ID_STR_LEN] = {0,};
 
-               tipc_nodeid2string(peer_str, peer_id);
-               if (strlen(peer_str) > 16)
+               if (tipc_nodeid2string(peer_str, peer_id) > NODE_ID_LEN)
                        sprintf(peer_str, "%x", peer);
                /* Broadcast receiver link name: "broadcast-link:<peer>" */
                snprintf(l->name, sizeof(l->name), "%s:%s", tipc_bclink_name,