[LLC]: Help the compiler with likely/unlikely, saving some more bytes

Signed-off-by: default avatarJochen Friedrich <jochen@scram.de>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@mandriva.com>
parent 0eb80172
...@@ -155,7 +155,7 @@ static int llc_ui_create(struct socket *sock, int protocol) ...@@ -155,7 +155,7 @@ static int llc_ui_create(struct socket *sock, int protocol)
struct sock *sk; struct sock *sk;
int rc = -ESOCKTNOSUPPORT; int rc = -ESOCKTNOSUPPORT;
if (sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM) { if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
rc = -ENOMEM; rc = -ENOMEM;
sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto); sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto);
if (sk) { if (sk) {
...@@ -177,7 +177,7 @@ static int llc_ui_release(struct socket *sock) ...@@ -177,7 +177,7 @@ static int llc_ui_release(struct socket *sock)
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct llc_sock *llc; struct llc_sock *llc;
if (!sk) if (unlikely(sk == NULL))
goto out; goto out;
sock_hold(sk); sock_hold(sk);
lock_sock(sk); lock_sock(sk);
...@@ -294,10 +294,10 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen) ...@@ -294,10 +294,10 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
int rc = -EINVAL; int rc = -EINVAL;
dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap); dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap);
if (!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)) if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
goto out; goto out;
rc = -EAFNOSUPPORT; rc = -EAFNOSUPPORT;
if (addr->sllc_family != AF_LLC) if (unlikely(addr->sllc_family != AF_LLC))
goto out; goto out;
if (!addr->sllc_sap) { if (!addr->sllc_sap) {
rc = -EUSERS; rc = -EUSERS;
...@@ -358,7 +358,7 @@ static int llc_ui_shutdown(struct socket *sock, int how) ...@@ -358,7 +358,7 @@ static int llc_ui_shutdown(struct socket *sock, int how)
int rc = -ENOTCONN; int rc = -ENOTCONN;
lock_sock(sk); lock_sock(sk);
if (sk->sk_state != TCP_ESTABLISHED) if (unlikely(sk->sk_state != TCP_ESTABLISHED))
goto out; goto out;
rc = -EINVAL; rc = -EINVAL;
if (how != 2) if (how != 2)
...@@ -396,10 +396,15 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -396,10 +396,15 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
int rc = -EINVAL; int rc = -EINVAL;
lock_sock(sk); lock_sock(sk);
if (addrlen != sizeof(*addr)) if (unlikely(addrlen != sizeof(*addr)))
goto out; goto out;
rc = -EAFNOSUPPORT; rc = -EAFNOSUPPORT;
if (addr->sllc_family != AF_LLC) if (unlikely(addr->sllc_family != AF_LLC))
goto out;
if (unlikely(sk->sk_type != SOCK_STREAM))
goto out;
rc = -EALREADY;
if (unlikely(sock->state == SS_CONNECTING))
goto out; goto out;
/* bind connection to sap if user hasn't done it. */ /* bind connection to sap if user hasn't done it. */
if (sock_flag(sk, SOCK_ZAPPED)) { if (sock_flag(sk, SOCK_ZAPPED)) {
...@@ -410,11 +415,6 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -410,11 +415,6 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
llc->daddr.lsap = addr->sllc_sap; llc->daddr.lsap = addr->sllc_sap;
memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN); memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
} }
if (sk->sk_type != SOCK_STREAM)
goto out;
rc = -EALREADY;
if (sock->state == SS_CONNECTING)
goto out;
sock->state = SS_CONNECTING; sock->state = SS_CONNECTING;
sk->sk_state = TCP_SYN_SENT; sk->sk_state = TCP_SYN_SENT;
llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap); llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
...@@ -448,10 +448,10 @@ static int llc_ui_listen(struct socket *sock, int backlog) ...@@ -448,10 +448,10 @@ static int llc_ui_listen(struct socket *sock, int backlog)
int rc = -EINVAL; int rc = -EINVAL;
lock_sock(sk); lock_sock(sk);
if (sock->state != SS_UNCONNECTED) if (unlikely(sock->state != SS_UNCONNECTED))
goto out; goto out;
rc = -EOPNOTSUPP; rc = -EOPNOTSUPP;
if (sk->sk_type != SOCK_STREAM) if (unlikely(sk->sk_type != SOCK_STREAM))
goto out; goto out;
rc = -EAGAIN; rc = -EAGAIN;
if (sock_flag(sk, SOCK_ZAPPED)) if (sock_flag(sk, SOCK_ZAPPED))
...@@ -614,10 +614,11 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -614,10 +614,11 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
dprintk("%s: accepting on %02X\n", __FUNCTION__, dprintk("%s: accepting on %02X\n", __FUNCTION__,
llc_sk(sk)->laddr.lsap); llc_sk(sk)->laddr.lsap);
lock_sock(sk); lock_sock(sk);
if (sk->sk_type != SOCK_STREAM) if (unlikely(sk->sk_type != SOCK_STREAM))
goto out; goto out;
rc = -EINVAL; rc = -EINVAL;
if (sock->state != SS_UNCONNECTED || sk->sk_state != TCP_LISTEN) if (unlikely(sock->state != SS_UNCONNECTED ||
sk->sk_state != TCP_LISTEN))
goto out; goto out;
/* wait for a connection to arrive. */ /* wait for a connection to arrive. */
rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo); rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo);
...@@ -880,7 +881,7 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname, ...@@ -880,7 +881,7 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
int rc = -EINVAL, opt; int rc = -EINVAL, opt;
lock_sock(sk); lock_sock(sk);
if (level != SOL_LLC || optlen != sizeof(int)) if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
goto out; goto out;
rc = get_user(opt, (int __user *)optval); rc = get_user(opt, (int __user *)optval);
if (rc) if (rc)
...@@ -955,7 +956,7 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname, ...@@ -955,7 +956,7 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
int val = 0, len = 0, rc = -EINVAL; int val = 0, len = 0, rc = -EINVAL;
lock_sock(sk); lock_sock(sk);
if (level != SOL_LLC) if (unlikely(level != SOL_LLC))
goto out; goto out;
rc = get_user(len, optlen); rc = get_user(len, optlen);
if (rc) if (rc)
......
...@@ -64,12 +64,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb) ...@@ -64,12 +64,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
skb_get(skb); skb_get(skb);
ev->ind_prim = ev->cfm_prim = 0; ev->ind_prim = ev->cfm_prim = 0;
rc = llc_conn_service(sk, skb); /* sending event to state machine */ rc = llc_conn_service(sk, skb); /* sending event to state machine */
if (rc) { if (unlikely(rc != 0)) {
printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__); printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__);
goto out_kfree_skb; goto out_kfree_skb;
} }
if (!ev->ind_prim && !ev->cfm_prim) { if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
/* indicate or confirm not required */ /* indicate or confirm not required */
/* XXX this is not very pretty, perhaps we should store /* XXX this is not very pretty, perhaps we should store
* XXX indicate/confirm-needed state in the llc_conn_state_ev * XXX indicate/confirm-needed state in the llc_conn_state_ev
...@@ -80,7 +80,7 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb) ...@@ -80,7 +80,7 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
goto out_skb_put; goto out_skb_put;
} }
if (ev->ind_prim && ev->cfm_prim) /* Paranoia */ if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
skb_get(skb); skb_get(skb);
switch (ev->ind_prim) { switch (ev->ind_prim) {
...@@ -762,14 +762,14 @@ static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -762,14 +762,14 @@ static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
int rc = 0; int rc = 0;
struct llc_sock *llc = llc_sk(sk); struct llc_sock *llc = llc_sk(sk);
if (llc_backlog_type(skb) == LLC_PACKET) { if (likely(llc_backlog_type(skb) == LLC_PACKET)) {
if (llc->state > 1) /* not closed */ if (likely(llc->state > 1)) /* not closed */
rc = llc_conn_rcv(sk, skb); rc = llc_conn_rcv(sk, skb);
else else
goto out_kfree_skb; goto out_kfree_skb;
} else if (llc_backlog_type(skb) == LLC_EVENT) { } else if (llc_backlog_type(skb) == LLC_EVENT) {
/* timer expiration event */ /* timer expiration event */
if (llc->state > 1) /* not closed */ if (likely(llc->state > 1)) /* not closed */
rc = llc_conn_state_process(sk, skb); rc = llc_conn_state_process(sk, skb);
else else
goto out_kfree_skb; goto out_kfree_skb;
......
...@@ -101,7 +101,7 @@ static inline int llc_fixup_skb(struct sk_buff *skb) ...@@ -101,7 +101,7 @@ static inline int llc_fixup_skb(struct sk_buff *skb)
u8 llc_len = 2; u8 llc_len = 2;
struct llc_pdu_sn *pdu; struct llc_pdu_sn *pdu;
if (!pskb_may_pull(skb, sizeof(*pdu))) if (unlikely(!pskb_may_pull(skb, sizeof(*pdu))))
return 0; return 0;
pdu = (struct llc_pdu_sn *)skb->data; pdu = (struct llc_pdu_sn *)skb->data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment