aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-06-25 21:41:31 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-27 15:50:54 -0400
commite4de5fab806f74622600ab7fd6ed22b7f911a8c5 (patch)
tree8027f61c6b6df7617e03fea860b3a803aa60c0a1 /net/tipc
parent3d09fc424406b5610964507b3eb73cebbc3b4c38 (diff)
tipc: use negative error return values in functions
In some places, TIPC functions returns positive integers as return codes. This goes against standard Linux coding practice, and may even cause problems in some cases. We now change the return values of the functions filter_rcv() and filter_connect() to become signed integers, and return negative error codes when needed. The codes we use in these particular cases are still TIPC specific, since they are both part of the TIPC API and have no correspondence in errno.h Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/socket.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index ef0475568f9e..9a95dab13b7e 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1269,17 +1269,16 @@ static void tipc_data_ready(struct sock *sk)
1269 * @tsk: TIPC socket 1269 * @tsk: TIPC socket
1270 * @msg: message 1270 * @msg: message
1271 * 1271 *
1272 * Returns TIPC error status code and socket error status code 1272 * Returns 0 (TIPC_OK) if everyting ok, -TIPC_ERR_NO_PORT otherwise
1273 * once it encounters some errors
1274 */ 1273 */
1275static u32 filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) 1274static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
1276{ 1275{
1277 struct sock *sk = &tsk->sk; 1276 struct sock *sk = &tsk->sk;
1278 struct tipc_port *port = &tsk->port; 1277 struct tipc_port *port = &tsk->port;
1279 struct socket *sock = sk->sk_socket; 1278 struct socket *sock = sk->sk_socket;
1280 struct tipc_msg *msg = buf_msg(*buf); 1279 struct tipc_msg *msg = buf_msg(*buf);
1281 1280
1282 u32 retval = TIPC_ERR_NO_PORT; 1281 int retval = -TIPC_ERR_NO_PORT;
1283 int res; 1282 int res;
1284 1283
1285 if (msg_mcast(msg)) 1284 if (msg_mcast(msg))
@@ -1382,32 +1381,33 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1382 * 1381 *
1383 * Called with socket lock already taken; port lock may also be taken. 1382 * Called with socket lock already taken; port lock may also be taken.
1384 * 1383 *
1385 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1384 * Returns 0 (TIPC_OK) if message was consumed, -TIPC error code if message
1385 * to be rejected.
1386 */ 1386 */
1387static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) 1387static int filter_rcv(struct sock *sk, struct sk_buff *buf)
1388{ 1388{
1389 struct socket *sock = sk->sk_socket; 1389 struct socket *sock = sk->sk_socket;
1390 struct tipc_sock *tsk = tipc_sk(sk); 1390 struct tipc_sock *tsk = tipc_sk(sk);
1391 struct tipc_msg *msg = buf_msg(buf); 1391 struct tipc_msg *msg = buf_msg(buf);
1392 unsigned int limit = rcvbuf_limit(sk, buf); 1392 unsigned int limit = rcvbuf_limit(sk, buf);
1393 u32 res = TIPC_OK; 1393 int rc = TIPC_OK;
1394 1394
1395 /* Reject message if it is wrong sort of message for socket */ 1395 /* Reject message if it is wrong sort of message for socket */
1396 if (msg_type(msg) > TIPC_DIRECT_MSG) 1396 if (msg_type(msg) > TIPC_DIRECT_MSG)
1397 return TIPC_ERR_NO_PORT; 1397 return -TIPC_ERR_NO_PORT;
1398 1398
1399 if (sock->state == SS_READY) { 1399 if (sock->state == SS_READY) {
1400 if (msg_connected(msg)) 1400 if (msg_connected(msg))
1401 return TIPC_ERR_NO_PORT; 1401 return -TIPC_ERR_NO_PORT;
1402 } else { 1402 } else {
1403 res = filter_connect(tsk, &buf); 1403 rc = filter_connect(tsk, &buf);
1404 if (res != TIPC_OK || buf == NULL) 1404 if (rc != TIPC_OK || buf == NULL)
1405 return res; 1405 return rc;
1406 } 1406 }
1407 1407
1408 /* Reject message if there isn't room to queue it */ 1408 /* Reject message if there isn't room to queue it */
1409 if (sk_rmem_alloc_get(sk) + buf->truesize >= limit) 1409 if (sk_rmem_alloc_get(sk) + buf->truesize >= limit)
1410 return TIPC_ERR_OVERLOAD; 1410 return -TIPC_ERR_OVERLOAD;
1411 1411
1412 /* Enqueue message */ 1412 /* Enqueue message */
1413 TIPC_SKB_CB(buf)->handle = NULL; 1413 TIPC_SKB_CB(buf)->handle = NULL;
@@ -1429,13 +1429,13 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1429 */ 1429 */
1430static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf) 1430static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf)
1431{ 1431{
1432 u32 res; 1432 int rc;
1433 struct tipc_sock *tsk = tipc_sk(sk); 1433 struct tipc_sock *tsk = tipc_sk(sk);
1434 uint truesize = buf->truesize; 1434 uint truesize = buf->truesize;
1435 1435
1436 res = filter_rcv(sk, buf); 1436 rc = filter_rcv(sk, buf);
1437 if (unlikely(res)) 1437 if (unlikely(rc))
1438 tipc_reject_msg(buf, res); 1438 tipc_reject_msg(buf, -rc);
1439 1439
1440 if (atomic_read(&tsk->dupl_rcvcnt) < TIPC_CONN_OVERLOAD_LIMIT) 1440 if (atomic_read(&tsk->dupl_rcvcnt) < TIPC_CONN_OVERLOAD_LIMIT)
1441 atomic_add(truesize, &tsk->dupl_rcvcnt); 1441 atomic_add(truesize, &tsk->dupl_rcvcnt);
@@ -1455,7 +1455,7 @@ int tipc_sk_rcv(struct sk_buff *buf)
1455 struct tipc_port *port; 1455 struct tipc_port *port;
1456 struct sock *sk; 1456 struct sock *sk;
1457 u32 dport = msg_destport(buf_msg(buf)); 1457 u32 dport = msg_destport(buf_msg(buf));
1458 int err = TIPC_OK; 1458 int rc = TIPC_OK;
1459 uint limit; 1459 uint limit;
1460 1460
1461 /* Forward unresolved named message */ 1461 /* Forward unresolved named message */
@@ -1467,7 +1467,7 @@ int tipc_sk_rcv(struct sk_buff *buf)
1467 /* Validate destination */ 1467 /* Validate destination */
1468 port = tipc_port_lock(dport); 1468 port = tipc_port_lock(dport);
1469 if (unlikely(!port)) { 1469 if (unlikely(!port)) {
1470 err = TIPC_ERR_NO_PORT; 1470 rc = -TIPC_ERR_NO_PORT;
1471 goto exit; 1471 goto exit;
1472 } 1472 }
1473 1473
@@ -1478,22 +1478,22 @@ int tipc_sk_rcv(struct sk_buff *buf)
1478 bh_lock_sock(sk); 1478 bh_lock_sock(sk);
1479 1479
1480 if (!sock_owned_by_user(sk)) { 1480 if (!sock_owned_by_user(sk)) {
1481 err = filter_rcv(sk, buf); 1481 rc = filter_rcv(sk, buf);
1482 } else { 1482 } else {
1483 if (sk->sk_backlog.len == 0) 1483 if (sk->sk_backlog.len == 0)
1484 atomic_set(&tsk->dupl_rcvcnt, 0); 1484 atomic_set(&tsk->dupl_rcvcnt, 0);
1485 limit = rcvbuf_limit(sk, buf) + atomic_read(&tsk->dupl_rcvcnt); 1485 limit = rcvbuf_limit(sk, buf) + atomic_read(&tsk->dupl_rcvcnt);
1486 if (sk_add_backlog(sk, buf, limit)) 1486 if (sk_add_backlog(sk, buf, limit))
1487 err = TIPC_ERR_OVERLOAD; 1487 rc = -TIPC_ERR_OVERLOAD;
1488 } 1488 }
1489 1489
1490 bh_unlock_sock(sk); 1490 bh_unlock_sock(sk);
1491 tipc_port_unlock(port); 1491 tipc_port_unlock(port);
1492 1492
1493 if (likely(!err)) 1493 if (likely(!rc))
1494 return 0; 1494 return 0;
1495exit: 1495exit:
1496 tipc_reject_msg(buf, err); 1496 tipc_reject_msg(buf, -rc);
1497 return -EHOSTUNREACH; 1497 return -EHOSTUNREACH;
1498} 1498}
1499 1499