Commit 0febc7b3 authored by Tom Parkin's avatar Tom Parkin Committed by David S. Miller

l2tp: cleanup comparisons to NULL

checkpatch warns about comparisons to NULL, e.g.

        CHECK: Comparison to NULL could be written "!rt"
        #474: FILE: net/l2tp/l2tp_ip.c:474:
        +       if (rt == NULL) {

These sort of comparisons are generally clearer and more readable
the way checkpatch suggests, so update l2tp accordingly.
Signed-off-by: default avatarTom Parkin <tparkin@katalix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 49b0aa1b
...@@ -412,7 +412,7 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff * ...@@ -412,7 +412,7 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff *
} }
/* call private receive handler */ /* call private receive handler */
if (session->recv_skb != NULL) if (session->recv_skb)
(*session->recv_skb)(session, skb, L2TP_SKB_CB(skb)->length); (*session->recv_skb)(session, skb, L2TP_SKB_CB(skb)->length);
else else
kfree_skb(skb); kfree_skb(skb);
...@@ -911,7 +911,7 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -911,7 +911,7 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
struct l2tp_tunnel *tunnel; struct l2tp_tunnel *tunnel;
tunnel = rcu_dereference_sk_user_data(sk); tunnel = rcu_dereference_sk_user_data(sk);
if (tunnel == NULL) if (!tunnel)
goto pass_up; goto pass_up;
l2tp_dbg(tunnel, L2TP_MSG_DATA, "%s: received %d bytes\n", l2tp_dbg(tunnel, L2TP_MSG_DATA, "%s: received %d bytes\n",
...@@ -1150,7 +1150,7 @@ static void l2tp_tunnel_destruct(struct sock *sk) ...@@ -1150,7 +1150,7 @@ static void l2tp_tunnel_destruct(struct sock *sk)
{ {
struct l2tp_tunnel *tunnel = l2tp_tunnel(sk); struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
if (tunnel == NULL) if (!tunnel)
goto end; goto end;
l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name);
...@@ -1189,7 +1189,7 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1189,7 +1189,7 @@ 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 == NULL); 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);
...@@ -1214,7 +1214,7 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1214,7 +1214,7 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
__l2tp_session_unhash(session); __l2tp_session_unhash(session);
l2tp_session_queue_purge(session); l2tp_session_queue_purge(session);
if (session->session_close != NULL) if (session->session_close)
(*session->session_close)(session); (*session->session_close)(session);
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
...@@ -1407,11 +1407,11 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 ...@@ -1407,11 +1407,11 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
int err; int err;
enum l2tp_encap_type encap = L2TP_ENCAPTYPE_UDP; enum l2tp_encap_type encap = L2TP_ENCAPTYPE_UDP;
if (cfg != NULL) if (cfg)
encap = cfg->encap; encap = cfg->encap;
tunnel = kzalloc(sizeof(struct l2tp_tunnel), GFP_KERNEL); tunnel = kzalloc(sizeof(struct l2tp_tunnel), GFP_KERNEL);
if (tunnel == NULL) { if (!tunnel) {
err = -ENOMEM; err = -ENOMEM;
goto err; goto err;
} }
...@@ -1426,7 +1426,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 ...@@ -1426,7 +1426,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
rwlock_init(&tunnel->hlist_lock); rwlock_init(&tunnel->hlist_lock);
tunnel->acpt_newsess = true; tunnel->acpt_newsess = true;
if (cfg != NULL) if (cfg)
tunnel->debug = cfg->debug; tunnel->debug = cfg->debug;
tunnel->encap = encap; tunnel->encap = encap;
...@@ -1615,7 +1615,7 @@ int l2tp_session_delete(struct l2tp_session *session) ...@@ -1615,7 +1615,7 @@ int l2tp_session_delete(struct l2tp_session *session)
__l2tp_session_unhash(session); __l2tp_session_unhash(session);
l2tp_session_queue_purge(session); l2tp_session_queue_purge(session);
if (session->session_close != NULL) if (session->session_close)
(*session->session_close)(session); (*session->session_close)(session);
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
...@@ -1648,7 +1648,7 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn ...@@ -1648,7 +1648,7 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
struct l2tp_session *session; struct l2tp_session *session;
session = kzalloc(sizeof(struct l2tp_session) + priv_size, GFP_KERNEL); session = kzalloc(sizeof(struct l2tp_session) + priv_size, GFP_KERNEL);
if (session != NULL) { if (session) {
session->magic = L2TP_SESSION_MAGIC; session->magic = L2TP_SESSION_MAGIC;
session->tunnel = tunnel; session->tunnel = tunnel;
......
...@@ -58,7 +58,7 @@ static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd) ...@@ -58,7 +58,7 @@ static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd)
pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx); pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
pd->session_idx++; pd->session_idx++;
if (pd->session == NULL) { if (!pd->session) {
pd->session_idx = 0; pd->session_idx = 0;
l2tp_dfs_next_tunnel(pd); l2tp_dfs_next_tunnel(pd);
} }
...@@ -72,16 +72,16 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) ...@@ -72,16 +72,16 @@ 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 == NULL); BUG_ON(!m->private);
pd = m->private; pd = m->private;
if (pd->tunnel == NULL) if (!pd->tunnel)
l2tp_dfs_next_tunnel(pd); l2tp_dfs_next_tunnel(pd);
else else
l2tp_dfs_next_session(pd); l2tp_dfs_next_session(pd);
/* NULL tunnel and session indicates end of list */ /* NULL tunnel and session indicates end of list */
if ((pd->tunnel == NULL) && (pd->session == NULL)) if (!pd->tunnel && !pd->session)
pd = NULL; pd = NULL;
out: out:
...@@ -221,7 +221,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) ...@@ -221,7 +221,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
atomic_long_read(&session->stats.rx_bytes), atomic_long_read(&session->stats.rx_bytes),
atomic_long_read(&session->stats.rx_errors)); atomic_long_read(&session->stats.rx_errors));
if (session->show != NULL) if (session->show)
session->show(m, session); session->show(m, session);
} }
...@@ -268,7 +268,7 @@ static int l2tp_dfs_seq_open(struct inode *inode, struct file *file) ...@@ -268,7 +268,7 @@ static int l2tp_dfs_seq_open(struct inode *inode, struct file *file)
int rc = -ENOMEM; int rc = -ENOMEM;
pd = kzalloc(sizeof(*pd), GFP_KERNEL); pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (pd == NULL) if (!pd)
goto out; goto out;
/* Derive the network namespace from the pid opening the /* Derive the network namespace from the pid opening the
......
...@@ -471,7 +471,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -471,7 +471,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
rt = (struct rtable *)__sk_dst_check(sk, 0); rt = (struct rtable *)__sk_dst_check(sk, 0);
rcu_read_lock(); rcu_read_lock();
if (rt == NULL) { if (!rt) {
const struct ip_options_rcu *inet_opt; const struct ip_options_rcu *inet_opt;
inet_opt = rcu_dereference(inet->inet_opt); inet_opt = rcu_dereference(inet->inet_opt);
......
...@@ -486,7 +486,7 @@ static int l2tp_ip6_push_pending_frames(struct sock *sk) ...@@ -486,7 +486,7 @@ static int l2tp_ip6_push_pending_frames(struct sock *sk)
int err = 0; int err = 0;
skb = skb_peek(&sk->sk_write_queue); skb = skb_peek(&sk->sk_write_queue);
if (skb == NULL) if (!skb)
goto out; goto out;
transhdr = (__be32 *)skb_transport_header(skb); transhdr = (__be32 *)skb_transport_header(skb);
......
...@@ -333,7 +333,7 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla ...@@ -333,7 +333,7 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
goto nla_put_failure; goto nla_put_failure;
nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS); nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
if (nest == NULL) if (!nest)
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS, if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
...@@ -475,7 +475,7 @@ static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback ...@@ -475,7 +475,7 @@ static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback
for (;;) { for (;;) {
tunnel = l2tp_tunnel_get_nth(net, ti); tunnel = l2tp_tunnel_get_nth(net, ti);
if (tunnel == NULL) if (!tunnel)
goto out; goto out;
if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid, if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid,
...@@ -598,14 +598,13 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf ...@@ -598,14 +598,13 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]); cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
if (l2tp_nl_cmd_ops[cfg.pw_type] == NULL) { if (!l2tp_nl_cmd_ops[cfg.pw_type]) {
genl_unlock(); genl_unlock();
request_module("net-l2tp-type-%u", cfg.pw_type); request_module("net-l2tp-type-%u", cfg.pw_type);
genl_lock(); genl_lock();
} }
#endif #endif
if ((l2tp_nl_cmd_ops[cfg.pw_type] == NULL) || if (!l2tp_nl_cmd_ops[cfg.pw_type] || !l2tp_nl_cmd_ops[cfg.pw_type]->session_create) {
(l2tp_nl_cmd_ops[cfg.pw_type]->session_create == NULL)) {
ret = -EPROTONOSUPPORT; ret = -EPROTONOSUPPORT;
goto out_tunnel; goto out_tunnel;
} }
...@@ -637,7 +636,7 @@ static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *inf ...@@ -637,7 +636,7 @@ static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *inf
u16 pw_type; u16 pw_type;
session = l2tp_nl_session_get(info); session = l2tp_nl_session_get(info);
if (session == NULL) { if (!session) {
ret = -ENODEV; ret = -ENODEV;
goto out; goto out;
} }
...@@ -662,7 +661,7 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf ...@@ -662,7 +661,7 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf
struct l2tp_session *session; struct l2tp_session *session;
session = l2tp_nl_session_get(info); session = l2tp_nl_session_get(info);
if (session == NULL) { if (!session) {
ret = -ENODEV; ret = -ENODEV;
goto out; goto out;
} }
...@@ -729,7 +728,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl ...@@ -729,7 +728,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
goto nla_put_failure; goto nla_put_failure;
nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS); nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
if (nest == NULL) if (!nest)
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS, if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
...@@ -774,7 +773,7 @@ static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info) ...@@ -774,7 +773,7 @@ static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info)
int ret; int ret;
session = l2tp_nl_session_get(info); session = l2tp_nl_session_get(info);
if (session == NULL) { if (!session) {
ret = -ENODEV; ret = -ENODEV;
goto err; goto err;
} }
...@@ -813,14 +812,14 @@ static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback ...@@ -813,14 +812,14 @@ static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback
int si = cb->args[1]; int si = cb->args[1];
for (;;) { for (;;) {
if (tunnel == NULL) { if (!tunnel) {
tunnel = l2tp_tunnel_get_nth(net, ti); tunnel = l2tp_tunnel_get_nth(net, ti);
if (tunnel == NULL) if (!tunnel)
goto out; goto out;
} }
session = l2tp_session_get_nth(tunnel, si); session = l2tp_session_get_nth(tunnel, si);
if (session == NULL) { if (!session) {
ti++; ti++;
l2tp_tunnel_dec_refcount(tunnel); l2tp_tunnel_dec_refcount(tunnel);
tunnel = NULL; tunnel = NULL;
......
...@@ -154,12 +154,12 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk) ...@@ -154,12 +154,12 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
{ {
struct l2tp_session *session; struct l2tp_session *session;
if (sk == NULL) if (!sk)
return NULL; return NULL;
sock_hold(sk); sock_hold(sk);
session = (struct l2tp_session *)(sk->sk_user_data); session = (struct l2tp_session *)(sk->sk_user_data);
if (session == NULL) { if (!session) {
sock_put(sk); sock_put(sk);
goto out; goto out;
} }
...@@ -217,7 +217,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int ...@@ -217,7 +217,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int
*/ */
rcu_read_lock(); rcu_read_lock();
sk = rcu_dereference(ps->sk); sk = rcu_dereference(ps->sk);
if (sk == NULL) if (!sk)
goto no_sock; goto no_sock;
/* If the first two bytes are 0xFF03, consider that it is the PPP's /* If the first two bytes are 0xFF03, consider that it is the PPP's
...@@ -285,7 +285,7 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m, ...@@ -285,7 +285,7 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
/* Get session and tunnel contexts */ /* Get session and tunnel contexts */
error = -EBADF; error = -EBADF;
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
if (session == NULL) if (!session)
goto error; goto error;
tunnel = session->tunnel; tunnel = session->tunnel;
...@@ -360,7 +360,7 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) ...@@ -360,7 +360,7 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
/* Get session and tunnel contexts from the socket */ /* Get session and tunnel contexts from the socket */
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
if (session == NULL) if (!session)
goto abort; goto abort;
tunnel = session->tunnel; tunnel = session->tunnel;
...@@ -703,7 +703,7 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr, ...@@ -703,7 +703,7 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
* tunnel id. * tunnel id.
*/ */
if (!info.session_id && !info.peer_session_id) { if (!info.session_id && !info.peer_session_id) {
if (tunnel == NULL) { if (!tunnel) {
struct l2tp_tunnel_cfg tcfg = { struct l2tp_tunnel_cfg tcfg = {
.encap = L2TP_ENCAPTYPE_UDP, .encap = L2TP_ENCAPTYPE_UDP,
.debug = 0, .debug = 0,
...@@ -738,11 +738,11 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr, ...@@ -738,11 +738,11 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
} else { } else {
/* Error if we can't find the tunnel */ /* Error if we can't find the tunnel */
error = -ENOENT; error = -ENOENT;
if (tunnel == NULL) if (!tunnel)
goto end; goto end;
/* Error if socket is not prepped */ /* Error if socket is not prepped */
if (tunnel->sock == NULL) if (!tunnel->sock)
goto end; goto end;
} }
...@@ -911,14 +911,14 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -911,14 +911,14 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
struct pppol2tp_session *pls; struct pppol2tp_session *pls;
error = -ENOTCONN; error = -ENOTCONN;
if (sk == NULL) if (!sk)
goto end; goto end;
if (!(sk->sk_state & PPPOX_CONNECTED)) if (!(sk->sk_state & PPPOX_CONNECTED))
goto end; goto end;
error = -EBADF; error = -EBADF;
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
if (session == NULL) if (!session)
goto end; goto end;
pls = l2tp_session_priv(session); pls = l2tp_session_priv(session);
...@@ -1263,13 +1263,13 @@ static int pppol2tp_setsockopt(struct socket *sock, int level, int optname, ...@@ -1263,13 +1263,13 @@ static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
return -EFAULT; return -EFAULT;
err = -ENOTCONN; err = -ENOTCONN;
if (sk->sk_user_data == NULL) if (!sk->sk_user_data)
goto end; goto end;
/* Get session context from the socket */ /* Get session context from the socket */
err = -EBADF; err = -EBADF;
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
if (session == NULL) if (!session)
goto end; goto end;
/* Special case: if session_id == 0x0000, treat as operation on tunnel /* Special case: if session_id == 0x0000, treat as operation on tunnel
...@@ -1382,13 +1382,13 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname, ...@@ -1382,13 +1382,13 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
return -EINVAL; return -EINVAL;
err = -ENOTCONN; err = -ENOTCONN;
if (sk->sk_user_data == NULL) if (!sk->sk_user_data)
goto end; goto end;
/* Get the session context */ /* Get the session context */
err = -EBADF; err = -EBADF;
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
if (session == NULL) if (!session)
goto end; goto end;
/* Special case: if session_id == 0x0000, treat as operation on tunnel */ /* Special case: if session_id == 0x0000, treat as operation on tunnel */
...@@ -1464,7 +1464,7 @@ static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd) ...@@ -1464,7 +1464,7 @@ static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx); pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
pd->session_idx++; pd->session_idx++;
if (pd->session == NULL) { if (!pd->session) {
pd->session_idx = 0; pd->session_idx = 0;
pppol2tp_next_tunnel(net, pd); pppol2tp_next_tunnel(net, pd);
} }
...@@ -1479,17 +1479,17 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs) ...@@ -1479,17 +1479,17 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
if (!pos) if (!pos)
goto out; goto out;
BUG_ON(m->private == NULL); BUG_ON(!m->private);
pd = m->private; pd = m->private;
net = seq_file_net(m); net = seq_file_net(m);
if (pd->tunnel == NULL) if (!pd->tunnel)
pppol2tp_next_tunnel(net, pd); pppol2tp_next_tunnel(net, pd);
else else
pppol2tp_next_session(net, pd); pppol2tp_next_session(net, pd);
/* NULL tunnel and session indicates end of list */ /* NULL tunnel and session indicates end of list */
if ((pd->tunnel == NULL) && (pd->session == NULL)) if (!pd->tunnel && !pd->session)
pd = NULL; pd = NULL;
out: out:
......
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