Commit a8cf7d03 authored by David S. Miller's avatar David S. Miller

Merge branch 'l2tp-avoid-multiple-assignment-remove-BUG_ON'

Tom Parkin says:

====================
l2tp: avoid multiple assignment, remove BUG_ON

l2tp hasn't been kept up to date with the static analysis checks offered
by checkpatch.pl.

This patchset builds on the series: "l2tp: cleanup checkpatch.pl
warnings" and "l2tp: further checkpatch.pl cleanups" to resolve some of
the remaining checkpatch warnings in l2tp.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents fb92f57b ab6934e0
...@@ -621,8 +621,8 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -621,8 +621,8 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
int length) int length)
{ {
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
u32 ns = 0, nr = 0;
int offset; int offset;
u32 ns, nr;
/* Parse and check optional cookie */ /* Parse and check optional cookie */
if (session->peer_cookie_len > 0) { if (session->peer_cookie_len > 0) {
...@@ -644,7 +644,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -644,7 +644,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
* the control of the LNS. If no sequence numbers present but * the control of the LNS. If no sequence numbers present but
* we were expecting them, discard frame. * we were expecting them, discard frame.
*/ */
ns = nr = 0;
L2TP_SKB_CB(skb)->has_seq = 0; L2TP_SKB_CB(skb)->has_seq = 0;
if (tunnel->version == L2TP_HDR_VER_2) { if (tunnel->version == L2TP_HDR_VER_2) {
if (hdrflags & L2TP_HDRFLAG_S) { if (hdrflags & L2TP_HDRFLAG_S) {
...@@ -774,17 +773,17 @@ EXPORT_SYMBOL(l2tp_recv_common); ...@@ -774,17 +773,17 @@ EXPORT_SYMBOL(l2tp_recv_common);
/* Drop skbs from the session's reorder_q /* Drop skbs from the session's reorder_q
*/ */
static int l2tp_session_queue_purge(struct l2tp_session *session) static void l2tp_session_queue_purge(struct l2tp_session *session)
{ {
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
BUG_ON(!session); if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
BUG_ON(session->magic != L2TP_SESSION_MAGIC); return;
while ((skb = skb_dequeue(&session->reorder_q))) { while ((skb = skb_dequeue(&session->reorder_q))) {
atomic_long_inc(&session->stats.rx_errors); atomic_long_inc(&session->stats.rx_errors);
kfree_skb(skb); kfree_skb(skb);
} }
return 0;
} }
/* Internal UDP receive frame. Do the real work of receiving an L2TP data frame /* Internal UDP receive frame. Do the real work of receiving an L2TP data frame
...@@ -826,7 +825,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) ...@@ -826,7 +825,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
} }
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = skb->data;
ptr = skb->data;
/* Get L2TP header flags */ /* Get L2TP header flags */
hdrflags = ntohs(*(__be16 *)ptr); hdrflags = ntohs(*(__be16 *)ptr);
...@@ -1189,8 +1189,6 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1189,8 +1189,6 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
struct hlist_node *tmp; struct hlist_node *tmp;
struct l2tp_session *session; struct l2tp_session *session;
BUG_ON(!tunnel);
l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n", l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n",
tunnel->name); tunnel->name);
...@@ -1565,13 +1563,13 @@ void l2tp_session_free(struct l2tp_session *session) ...@@ -1565,13 +1563,13 @@ void l2tp_session_free(struct l2tp_session *session)
{ {
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
BUG_ON(refcount_read(&session->ref_count) != 0);
if (tunnel) { if (tunnel) {
BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); if (WARN_ON(tunnel->magic != L2TP_TUNNEL_MAGIC))
goto out;
l2tp_tunnel_dec_refcount(tunnel); l2tp_tunnel_dec_refcount(tunnel);
} }
out:
kfree(session); kfree(session);
} }
EXPORT_SYMBOL_GPL(l2tp_session_free); EXPORT_SYMBOL_GPL(l2tp_session_free);
......
...@@ -72,7 +72,10 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) ...@@ -72,7 +72,10 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
if (!pos) if (!pos)
goto out; goto out;
BUG_ON(!m->private); if (WARN_ON(!m->private)) {
pd = NULL;
goto out;
}
pd = m->private; pd = m->private;
if (!pd->tunnel) if (!pd->tunnel)
......
...@@ -124,7 +124,8 @@ static int l2tp_ip_recv(struct sk_buff *skb) ...@@ -124,7 +124,8 @@ static int l2tp_ip_recv(struct sk_buff *skb)
goto discard; goto discard;
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = skb->data;
ptr = skb->data;
session_id = ntohl(*((__be32 *)ptr)); session_id = ntohl(*((__be32 *)ptr));
ptr += 4; ptr += 4;
...@@ -153,7 +154,8 @@ static int l2tp_ip_recv(struct sk_buff *skb) ...@@ -153,7 +154,8 @@ static int l2tp_ip_recv(struct sk_buff *skb)
goto discard_sess; goto discard_sess;
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = skb->data;
ptr = skb->data;
ptr += 4; ptr += 4;
pr_debug("%s: ip recv\n", tunnel->name); pr_debug("%s: ip recv\n", tunnel->name);
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length); print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
...@@ -284,8 +286,10 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -284,8 +286,10 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
goto out; goto out;
if (addr->l2tp_addr.s_addr) if (addr->l2tp_addr.s_addr) {
inet->inet_rcv_saddr = inet->inet_saddr = addr->l2tp_addr.s_addr; inet->inet_rcv_saddr = addr->l2tp_addr.s_addr;
inet->inet_saddr = addr->l2tp_addr.s_addr;
}
if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
inet->inet_saddr = 0; /* Use device */ inet->inet_saddr = 0; /* Use device */
......
...@@ -137,7 +137,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb) ...@@ -137,7 +137,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
goto discard; goto discard;
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = skb->data;
ptr = skb->data;
session_id = ntohl(*((__be32 *)ptr)); session_id = ntohl(*((__be32 *)ptr));
ptr += 4; ptr += 4;
...@@ -166,7 +167,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb) ...@@ -166,7 +167,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
goto discard_sess; goto discard_sess;
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = skb->data;
ptr = skb->data;
ptr += 4; ptr += 4;
pr_debug("%s: ip recv\n", tunnel->name); pr_debug("%s: ip recv\n", tunnel->name);
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length); print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
......
...@@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk) ...@@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
sock_put(sk); sock_put(sk);
goto out; goto out;
} }
if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) {
BUG_ON(session->magic != L2TP_SESSION_MAGIC); session = NULL;
sock_put(sk);
goto out;
}
out: out:
return session; return session;
...@@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk) ...@@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk)
if (session) { if (session) {
sk->sk_user_data = NULL; sk->sk_user_data = NULL;
BUG_ON(session->magic != L2TP_SESSION_MAGIC); if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
return;
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
} }
} }
...@@ -1474,7 +1478,11 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs) ...@@ -1474,7 +1478,11 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
if (!pos) if (!pos)
goto out; goto out;
BUG_ON(!m->private); if (WARN_ON(!m->private)) {
pd = NULL;
goto out;
}
pd = m->private; pd = m->private;
net = seq_file_net(m); net = seq_file_net(m);
......
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