Skip to content

Commit 0ec01d1

Browse files
tomparkinintel-lab-lkp
authored andcommitted
l2tp: cleanup comparisons to NULL
checkpatch warns about comparisons to NULL, e.g. CHECK: Comparison to NULL could be written "!rt" torvalds#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: Tom Parkin <[email protected]>
1 parent e907abd commit 0ec01d1

File tree

6 files changed

+47
-48
lines changed

6 files changed

+47
-48
lines changed

net/l2tp/l2tp_core.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff *
410410
}
411411

412412
/* call private receive handler */
413-
if (session->recv_skb != NULL)
413+
if (session->recv_skb)
414414
(*session->recv_skb)(session, skb, L2TP_SKB_CB(skb)->length);
415415
else
416416
kfree_skb(skb);
@@ -909,7 +909,7 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
909909
struct l2tp_tunnel *tunnel;
910910

911911
tunnel = rcu_dereference_sk_user_data(sk);
912-
if (tunnel == NULL)
912+
if (!tunnel)
913913
goto pass_up;
914914

915915
l2tp_dbg(tunnel, L2TP_MSG_DATA, "%s: received %d bytes\n",
@@ -1148,7 +1148,7 @@ static void l2tp_tunnel_destruct(struct sock *sk)
11481148
{
11491149
struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
11501150

1151-
if (tunnel == NULL)
1151+
if (!tunnel)
11521152
goto end;
11531153

11541154
l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name);
@@ -1187,7 +1187,7 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
11871187
struct hlist_node *tmp;
11881188
struct l2tp_session *session;
11891189

1190-
BUG_ON(tunnel == NULL);
1190+
BUG_ON(!tunnel);
11911191

11921192
l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n",
11931193
tunnel->name);
@@ -1212,7 +1212,7 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
12121212
__l2tp_session_unhash(session);
12131213
l2tp_session_queue_purge(session);
12141214

1215-
if (session->session_close != NULL)
1215+
if (session->session_close)
12161216
(*session->session_close)(session);
12171217

12181218
l2tp_session_dec_refcount(session);
@@ -1404,11 +1404,11 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
14041404
int err;
14051405
enum l2tp_encap_type encap = L2TP_ENCAPTYPE_UDP;
14061406

1407-
if (cfg != NULL)
1407+
if (cfg)
14081408
encap = cfg->encap;
14091409

14101410
tunnel = kzalloc(sizeof(struct l2tp_tunnel), GFP_KERNEL);
1411-
if (tunnel == NULL) {
1411+
if (!tunnel) {
14121412
err = -ENOMEM;
14131413
goto err;
14141414
}
@@ -1423,7 +1423,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
14231423
rwlock_init(&tunnel->hlist_lock);
14241424
tunnel->acpt_newsess = true;
14251425

1426-
if (cfg != NULL)
1426+
if (cfg)
14271427
tunnel->debug = cfg->debug;
14281428

14291429
tunnel->encap = encap;
@@ -1612,7 +1612,7 @@ int l2tp_session_delete(struct l2tp_session *session)
16121612

16131613
__l2tp_session_unhash(session);
16141614
l2tp_session_queue_purge(session);
1615-
if (session->session_close != NULL)
1615+
if (session->session_close)
16161616
(*session->session_close)(session);
16171617

16181618
l2tp_session_dec_refcount(session);
@@ -1644,7 +1644,7 @@ struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunn
16441644
struct l2tp_session *session;
16451645

16461646
session = kzalloc(sizeof(struct l2tp_session) + priv_size, GFP_KERNEL);
1647-
if (session != NULL) {
1647+
if (session) {
16481648
session->magic = L2TP_SESSION_MAGIC;
16491649
session->tunnel = tunnel;
16501650

net/l2tp/l2tp_debugfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd)
5858
pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
5959
pd->session_idx++;
6060

61-
if (pd->session == NULL) {
61+
if (!pd->session) {
6262
pd->session_idx = 0;
6363
l2tp_dfs_next_tunnel(pd);
6464
}
@@ -72,16 +72,16 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
7272
if (!pos)
7373
goto out;
7474

75-
BUG_ON(m->private == NULL);
75+
BUG_ON(!m->private);
7676
pd = m->private;
7777

78-
if (pd->tunnel == NULL)
78+
if (!pd->tunnel)
7979
l2tp_dfs_next_tunnel(pd);
8080
else
8181
l2tp_dfs_next_session(pd);
8282

8383
/* NULL tunnel and session indicates end of list */
84-
if ((pd->tunnel == NULL) && (pd->session == NULL))
84+
if (!pd->tunnel && !pd->session)
8585
pd = NULL;
8686

8787
out:
@@ -221,7 +221,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
221221
atomic_long_read(&session->stats.rx_bytes),
222222
atomic_long_read(&session->stats.rx_errors));
223223

224-
if (session->show != NULL)
224+
if (session->show)
225225
session->show(m, session);
226226
}
227227

@@ -268,7 +268,7 @@ static int l2tp_dfs_seq_open(struct inode *inode, struct file *file)
268268
int rc = -ENOMEM;
269269

270270
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
271-
if (pd == NULL)
271+
if (!pd)
272272
goto out;
273273

274274
/* Derive the network namespace from the pid opening the

net/l2tp/l2tp_ip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
471471
rt = (struct rtable *)__sk_dst_check(sk, 0);
472472

473473
rcu_read_lock();
474-
if (rt == NULL) {
474+
if (!rt) {
475475
const struct ip_options_rcu *inet_opt;
476476

477477
inet_opt = rcu_dereference(inet->inet_opt);

net/l2tp/l2tp_ip6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int l2tp_ip6_push_pending_frames(struct sock *sk)
486486
int err = 0;
487487

488488
skb = skb_peek(&sk->sk_write_queue);
489-
if (skb == NULL)
489+
if (!skb)
490490
goto out;
491491

492492
transhdr = (__be32 *)skb_transport_header(skb);

net/l2tp/l2tp_netlink.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
333333
goto nla_put_failure;
334334

335335
nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
336-
if (nest == NULL)
336+
if (!nest)
337337
goto nla_put_failure;
338338

339339
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
475475

476476
for (;;) {
477477
tunnel = l2tp_tunnel_get_nth(net, ti);
478-
if (tunnel == NULL)
478+
if (!tunnel)
479479
goto out;
480480

481481
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
598598
cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
599599

600600
#ifdef CONFIG_MODULES
601-
if (l2tp_nl_cmd_ops[cfg.pw_type] == NULL) {
601+
if (!l2tp_nl_cmd_ops[cfg.pw_type]) {
602602
genl_unlock();
603603
request_module("net-l2tp-type-%u", cfg.pw_type);
604604
genl_lock();
605605
}
606606
#endif
607-
if ((l2tp_nl_cmd_ops[cfg.pw_type] == NULL) ||
608-
(l2tp_nl_cmd_ops[cfg.pw_type]->session_create == NULL)) {
607+
if (!l2tp_nl_cmd_ops[cfg.pw_type] || !l2tp_nl_cmd_ops[cfg.pw_type]->session_create) {
609608
ret = -EPROTONOSUPPORT;
610609
goto out_tunnel;
611610
}
@@ -637,7 +636,7 @@ static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *inf
637636
u16 pw_type;
638637

639638
session = l2tp_nl_session_get(info);
640-
if (session == NULL) {
639+
if (!session) {
641640
ret = -ENODEV;
642641
goto out;
643642
}
@@ -662,7 +661,7 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf
662661
struct l2tp_session *session;
663662

664663
session = l2tp_nl_session_get(info);
665-
if (session == NULL) {
664+
if (!session) {
666665
ret = -ENODEV;
667666
goto out;
668667
}
@@ -729,7 +728,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
729728
goto nla_put_failure;
730729

731730
nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
732-
if (nest == NULL)
731+
if (!nest)
733732
goto nla_put_failure;
734733

735734
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)
774773
int ret;
775774

776775
session = l2tp_nl_session_get(info);
777-
if (session == NULL) {
776+
if (!session) {
778777
ret = -ENODEV;
779778
goto err;
780779
}
@@ -813,14 +812,14 @@ static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback
813812
int si = cb->args[1];
814813

815814
for (;;) {
816-
if (tunnel == NULL) {
815+
if (!tunnel) {
817816
tunnel = l2tp_tunnel_get_nth(net, ti);
818-
if (tunnel == NULL)
817+
if (!tunnel)
819818
goto out;
820819
}
821820

822821
session = l2tp_session_get_nth(tunnel, si);
823-
if (session == NULL) {
822+
if (!session) {
824823
ti++;
825824
l2tp_tunnel_dec_refcount(tunnel);
826825
tunnel = NULL;

net/l2tp/l2tp_ppp.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
154154
{
155155
struct l2tp_session *session;
156156

157-
if (sk == NULL)
157+
if (!sk)
158158
return NULL;
159159

160160
sock_hold(sk);
161161
session = (struct l2tp_session *)(sk->sk_user_data);
162-
if (session == NULL) {
162+
if (!session) {
163163
sock_put(sk);
164164
goto out;
165165
}
@@ -217,7 +217,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int
217217
*/
218218
rcu_read_lock();
219219
sk = rcu_dereference(ps->sk);
220-
if (sk == NULL)
220+
if (!sk)
221221
goto no_sock;
222222

223223
/* 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,
285285
/* Get session and tunnel contexts */
286286
error = -EBADF;
287287
session = pppol2tp_sock_to_session(sk);
288-
if (session == NULL)
288+
if (!session)
289289
goto error;
290290

291291
tunnel = session->tunnel;
@@ -360,7 +360,7 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
360360

361361
/* Get session and tunnel contexts from the socket */
362362
session = pppol2tp_sock_to_session(sk);
363-
if (session == NULL)
363+
if (!session)
364364
goto abort;
365365

366366
tunnel = session->tunnel;
@@ -703,7 +703,7 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
703703
* tunnel id.
704704
*/
705705
if (!info.session_id && !info.peer_session_id) {
706-
if (tunnel == NULL) {
706+
if (!tunnel) {
707707
struct l2tp_tunnel_cfg tcfg = {
708708
.encap = L2TP_ENCAPTYPE_UDP,
709709
.debug = 0,
@@ -738,11 +738,11 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
738738
} else {
739739
/* Error if we can't find the tunnel */
740740
error = -ENOENT;
741-
if (tunnel == NULL)
741+
if (!tunnel)
742742
goto end;
743743

744744
/* Error if socket is not prepped */
745-
if (tunnel->sock == NULL)
745+
if (!tunnel->sock)
746746
goto end;
747747
}
748748

@@ -911,14 +911,14 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
911911
struct pppol2tp_session *pls;
912912

913913
error = -ENOTCONN;
914-
if (sk == NULL)
914+
if (!sk)
915915
goto end;
916916
if (!(sk->sk_state & PPPOX_CONNECTED))
917917
goto end;
918918

919919
error = -EBADF;
920920
session = pppol2tp_sock_to_session(sk);
921-
if (session == NULL)
921+
if (!session)
922922
goto end;
923923

924924
pls = l2tp_session_priv(session);
@@ -1263,13 +1263,13 @@ static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
12631263
return -EFAULT;
12641264

12651265
err = -ENOTCONN;
1266-
if (sk->sk_user_data == NULL)
1266+
if (!sk->sk_user_data)
12671267
goto end;
12681268

12691269
/* Get session context from the socket */
12701270
err = -EBADF;
12711271
session = pppol2tp_sock_to_session(sk);
1272-
if (session == NULL)
1272+
if (!session)
12731273
goto end;
12741274

12751275
/* 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,
13821382
return -EINVAL;
13831383

13841384
err = -ENOTCONN;
1385-
if (sk->sk_user_data == NULL)
1385+
if (!sk->sk_user_data)
13861386
goto end;
13871387

13881388
/* Get the session context */
13891389
err = -EBADF;
13901390
session = pppol2tp_sock_to_session(sk);
1391-
if (session == NULL)
1391+
if (!session)
13921392
goto end;
13931393

13941394
/* 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)
14641464
pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
14651465
pd->session_idx++;
14661466

1467-
if (pd->session == NULL) {
1467+
if (!pd->session) {
14681468
pd->session_idx = 0;
14691469
pppol2tp_next_tunnel(net, pd);
14701470
}
@@ -1479,17 +1479,17 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
14791479
if (!pos)
14801480
goto out;
14811481

1482-
BUG_ON(m->private == NULL);
1482+
BUG_ON(!m->private);
14831483
pd = m->private;
14841484
net = seq_file_net(m);
14851485

1486-
if (pd->tunnel == NULL)
1486+
if (!pd->tunnel)
14871487
pppol2tp_next_tunnel(net, pd);
14881488
else
14891489
pppol2tp_next_session(net, pd);
14901490

14911491
/* NULL tunnel and session indicates end of list */
1492-
if ((pd->tunnel == NULL) && (pd->session == NULL))
1492+
if (!pd->tunnel && !pd->session)
14931493
pd = NULL;
14941494

14951495
out:

0 commit comments

Comments
 (0)