提交 2db9983a 编写于 作者: A Allan Stephens 提交者: David S. Miller

tipc: split variable assignments out of conditional expressions

Cleans up TIPC's source code to eliminate assigning values to variables
within conditional expressions, improving code readability and reducing
warnings from various code checker tools.

These changes are purely cosmetic and do not alter the operation of TIPC
in any way.
Signed-off-by: NAllan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: NPaul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 0e65967e
...@@ -251,7 +251,8 @@ static int bearer_name_validate(const char *name, ...@@ -251,7 +251,8 @@ static int bearer_name_validate(const char *name,
/* ensure all component parts of bearer name are present */ /* ensure all component parts of bearer name are present */
media_name = name_copy; media_name = name_copy;
if ((if_name = strchr(media_name, ':')) == NULL) if_name = strchr(media_name, ':');
if (if_name == NULL)
return 0; return 0;
*(if_name++) = 0; *(if_name++) = 0;
media_len = if_name - media_name; media_len = if_name - media_name;
......
...@@ -115,10 +115,11 @@ int tipc_core_start_net(unsigned long addr) ...@@ -115,10 +115,11 @@ int tipc_core_start_net(unsigned long addr)
{ {
int res; int res;
if ((res = tipc_net_start(addr)) || res = tipc_net_start(addr);
(res = tipc_eth_media_start())) { if (!res)
res = tipc_eth_media_start();
if (res)
tipc_core_stop_net(); tipc_core_stop_net();
}
return res; return res;
} }
...@@ -157,15 +158,22 @@ static int tipc_core_start(void) ...@@ -157,15 +158,22 @@ static int tipc_core_start(void)
get_random_bytes(&tipc_random, sizeof(tipc_random)); get_random_bytes(&tipc_random, sizeof(tipc_random));
tipc_mode = TIPC_NODE_MODE; tipc_mode = TIPC_NODE_MODE;
if ((res = tipc_handler_start()) || res = tipc_handler_start();
(res = tipc_ref_table_init(tipc_max_ports, tipc_random)) || if (!res)
(res = tipc_nametbl_init()) || res = tipc_ref_table_init(tipc_max_ports, tipc_random);
(res = tipc_k_signal((Handler)tipc_subscr_start, 0)) || if (!res)
(res = tipc_k_signal((Handler)tipc_cfg_init, 0)) || res = tipc_nametbl_init();
(res = tipc_netlink_start()) || if (!res)
(res = tipc_socket_init())) { res = tipc_k_signal((Handler)tipc_subscr_start, 0);
if (!res)
res = tipc_k_signal((Handler)tipc_cfg_init, 0);
if (!res)
res = tipc_netlink_start();
if (!res)
res = tipc_socket_init();
if (res)
tipc_core_stop(); tipc_core_stop();
}
return res; return res;
} }
...@@ -188,7 +196,8 @@ static int __init tipc_init(void) ...@@ -188,7 +196,8 @@ static int __init tipc_init(void)
tipc_max_nodes = CONFIG_TIPC_NODES; tipc_max_nodes = CONFIG_TIPC_NODES;
tipc_net_id = 4711; tipc_net_id = 4711;
if ((res = tipc_core_start())) res = tipc_core_start();
if (res)
err("Unable to start in single node mode\n"); err("Unable to start in single node mode\n");
else else
info("Started in single node mode\n"); info("Started in single node mode\n");
......
...@@ -187,14 +187,17 @@ static int link_name_validate(const char *name, struct link_name *name_parts) ...@@ -187,14 +187,17 @@ static int link_name_validate(const char *name, struct link_name *name_parts)
/* ensure all component parts of link name are present */ /* ensure all component parts of link name are present */
addr_local = name_copy; addr_local = name_copy;
if ((if_local = strchr(addr_local, ':')) == NULL) if_local = strchr(addr_local, ':');
if (if_local == NULL)
return 0; return 0;
*(if_local++) = 0; *(if_local++) = 0;
if ((addr_peer = strchr(if_local, '-')) == NULL) addr_peer = strchr(if_local, '-');
if (addr_peer == NULL)
return 0; return 0;
*(addr_peer++) = 0; *(addr_peer++) = 0;
if_local_len = addr_peer - if_local; if_local_len = addr_peer - if_local;
if ((if_peer = strchr(addr_peer, ':')) == NULL) if_peer = strchr(addr_peer, ':');
if (if_peer == NULL)
return 0; return 0;
*(if_peer++) = 0; *(if_peer++) = 0;
if_peer_len = strlen(if_peer) + 1; if_peer_len = strlen(if_peer) + 1;
...@@ -2044,8 +2047,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf) ...@@ -2044,8 +2047,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg)); strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
if ((msg_tol = msg_link_tolerance(msg)) && msg_tol = msg_link_tolerance(msg);
(msg_tol > l_ptr->tolerance)) if (msg_tol > l_ptr->tolerance)
link_set_supervision_props(l_ptr, msg_tol); link_set_supervision_props(l_ptr, msg_tol);
if (msg_linkprio(msg) > l_ptr->priority) if (msg_linkprio(msg) > l_ptr->priority)
...@@ -2074,7 +2077,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf) ...@@ -2074,7 +2077,8 @@ static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
break; break;
case STATE_MSG: case STATE_MSG:
if ((msg_tol = msg_link_tolerance(msg))) msg_tol = msg_link_tolerance(msg);
if (msg_tol)
link_set_supervision_props(l_ptr, msg_tol); link_set_supervision_props(l_ptr, msg_tol);
if (msg_linkprio(msg) && if (msg_linkprio(msg) &&
......
...@@ -563,7 +563,8 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -563,7 +563,8 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
do { do {
if (dest->addrtype == TIPC_ADDR_NAME) { if (dest->addrtype == TIPC_ADDR_NAME) {
if ((res = dest_name_check(dest, m))) res = dest_name_check(dest, m);
if (res)
break; break;
res = tipc_send2name(tport->ref, res = tipc_send2name(tport->ref,
&dest->addr.name.name, &dest->addr.name.name,
...@@ -580,7 +581,8 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -580,7 +581,8 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
res = -EOPNOTSUPP; res = -EOPNOTSUPP;
break; break;
} }
if ((res = dest_name_check(dest, m))) res = dest_name_check(dest, m);
if (res)
break; break;
res = tipc_multicast(tport->ref, res = tipc_multicast(tport->ref,
&dest->addr.nameseq, &dest->addr.nameseq,
...@@ -750,7 +752,8 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, ...@@ -750,7 +752,8 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
bytes_to_send = curr_left; bytes_to_send = curr_left;
my_iov.iov_base = curr_start; my_iov.iov_base = curr_start;
my_iov.iov_len = bytes_to_send; my_iov.iov_len = bytes_to_send;
if ((res = send_packet(NULL, sock, &my_msg, 0)) < 0) { res = send_packet(NULL, sock, &my_msg, 0);
if (res < 0) {
if (bytes_sent) if (bytes_sent)
res = bytes_sent; res = bytes_sent;
goto exit; goto exit;
...@@ -845,12 +848,15 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, ...@@ -845,12 +848,15 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
if (unlikely(err)) { if (unlikely(err)) {
anc_data[0] = err; anc_data[0] = err;
anc_data[1] = msg_data_sz(msg); anc_data[1] = msg_data_sz(msg);
if ((res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data))) res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data);
return res; if (res)
if (anc_data[1] &&
(res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1],
msg_data(msg))))
return res; return res;
if (anc_data[1]) {
res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1],
msg_data(msg));
if (res)
return res;
}
} }
/* Optionally capture message destination object */ /* Optionally capture message destination object */
...@@ -878,9 +884,11 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, ...@@ -878,9 +884,11 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
default: default:
has_name = 0; has_name = 0;
} }
if (has_name && if (has_name) {
(res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data))) res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data);
return res; if (res)
return res;
}
return 0; return 0;
} }
...@@ -1664,7 +1672,8 @@ static int setsockopt(struct socket *sock, ...@@ -1664,7 +1672,8 @@ static int setsockopt(struct socket *sock,
return -ENOPROTOOPT; return -ENOPROTOOPT;
if (ol < sizeof(value)) if (ol < sizeof(value))
return -EINVAL; return -EINVAL;
if ((res = get_user(value, (u32 __user *)ov))) res = get_user(value, (u32 __user *)ov);
if (res)
return res; return res;
lock_sock(sk); lock_sock(sk);
...@@ -1722,7 +1731,8 @@ static int getsockopt(struct socket *sock, ...@@ -1722,7 +1731,8 @@ static int getsockopt(struct socket *sock,
return put_user(0, ol); return put_user(0, ol);
if (lvl != SOL_TIPC) if (lvl != SOL_TIPC)
return -ENOPROTOOPT; return -ENOPROTOOPT;
if ((res = get_user(len, ol))) res = get_user(len, ol);
if (res)
return res; return res;
lock_sock(sk); lock_sock(sk);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册