Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tipc: adjust tipc_nodeid2string() to return string length

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>

authored by

Dmitry Antipov and committed by
Paolo Abeni
2ade9170 38b04ed7

+7 -10
+3 -3
net/tipc/addr.c
··· 79 79 pr_info("Node number set to %u\n", addr); 80 80 } 81 81 82 - char *tipc_nodeid2string(char *str, u8 *id) 82 + int tipc_nodeid2string(char *str, u8 *id) 83 83 { 84 84 int i; 85 85 u8 c; ··· 109 109 if (i == NODE_ID_LEN) { 110 110 memcpy(str, id, NODE_ID_LEN); 111 111 str[NODE_ID_LEN] = 0; 112 - return str; 112 + return i; 113 113 } 114 114 115 115 /* Translate to hex string */ ··· 120 120 for (i = NODE_ID_STR_LEN - 2; str[i] == '0'; i--) 121 121 str[i] = 0; 122 122 123 - return str; 123 + return i + 1; 124 124 }
+1 -1
net/tipc/addr.h
··· 130 130 bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr); 131 131 void tipc_set_node_id(struct net *net, u8 *id); 132 132 void tipc_set_node_addr(struct net *net, u32 addr); 133 - char *tipc_nodeid2string(char *str, u8 *id); 133 + int tipc_nodeid2string(char *str, u8 *id); 134 134 135 135 #endif
+3 -6
net/tipc/link.c
··· 495 495 496 496 /* Set link name for unicast links only */ 497 497 if (peer_id) { 498 - tipc_nodeid2string(self_str, tipc_own_id(net)); 499 - if (strlen(self_str) > 16) 498 + if (tipc_nodeid2string(self_str, tipc_own_id(net)) > NODE_ID_LEN) 500 499 sprintf(self_str, "%x", self); 501 - tipc_nodeid2string(peer_str, peer_id); 502 - if (strlen(peer_str) > 16) 500 + if (tipc_nodeid2string(peer_str, peer_id) > NODE_ID_LEN) 503 501 sprintf(peer_str, "%x", peer); 504 502 } 505 503 /* Peer i/f name will be completed by reset/activate message */ ··· 568 570 if (peer_id) { 569 571 char peer_str[NODE_ID_STR_LEN] = {0,}; 570 572 571 - tipc_nodeid2string(peer_str, peer_id); 572 - if (strlen(peer_str) > 16) 573 + if (tipc_nodeid2string(peer_str, peer_id) > NODE_ID_LEN) 573 574 sprintf(peer_str, "%x", peer); 574 575 /* Broadcast receiver link name: "broadcast-link:<peer>" */ 575 576 snprintf(l->name, sizeof(l->name), "%s:%s", tipc_bclink_name,