Skip to content

Commit 2ade917

Browse files
dmantipovPaolo Abeni
authored andcommitted
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>
1 parent 38b04ed commit 2ade917

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

net/tipc/addr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void tipc_set_node_addr(struct net *net, u32 addr)
7979
pr_info("Node number set to %u\n", addr);
8080
}
8181

82-
char *tipc_nodeid2string(char *str, u8 *id)
82+
int tipc_nodeid2string(char *str, u8 *id)
8383
{
8484
int i;
8585
u8 c;
@@ -109,7 +109,7 @@ char *tipc_nodeid2string(char *str, u8 *id)
109109
if (i == NODE_ID_LEN) {
110110
memcpy(str, id, NODE_ID_LEN);
111111
str[NODE_ID_LEN] = 0;
112-
return str;
112+
return i;
113113
}
114114

115115
/* Translate to hex string */
@@ -120,5 +120,5 @@ char *tipc_nodeid2string(char *str, u8 *id)
120120
for (i = NODE_ID_STR_LEN - 2; str[i] == '0'; i--)
121121
str[i] = 0;
122122

123-
return str;
123+
return i + 1;
124124
}

net/tipc/addr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ static inline int in_own_node(struct net *net, u32 addr)
130130
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
131131
void tipc_set_node_id(struct net *net, u8 *id);
132132
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);
134134

135135
#endif

net/tipc/link.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,9 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
495495

496496
/* Set link name for unicast links only */
497497
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)
500499
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)
503501
sprintf(peer_str, "%x", peer);
504502
}
505503
/* 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,
570568
if (peer_id) {
571569
char peer_str[NODE_ID_STR_LEN] = {0,};
572570

573-
tipc_nodeid2string(peer_str, peer_id);
574-
if (strlen(peer_str) > 16)
571+
if (tipc_nodeid2string(peer_str, peer_id) > NODE_ID_LEN)
575572
sprintf(peer_str, "%x", peer);
576573
/* Broadcast receiver link name: "broadcast-link:<peer>" */
577574
snprintf(l->name, sizeof(l->name), "%s:%s", tipc_bclink_name,

0 commit comments

Comments
 (0)