All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Simplify NULL comparisons
@ 2017-04-01 16:13 Arushi Singhal
  2017-04-01 16:13 ` [PATCH 1/2] ipv4: netfilter: " Arushi Singhal
  2017-04-01 16:13 ` [PATCH 2/2] ipv6: " Arushi Singhal
  0 siblings, 2 replies; 4+ messages in thread
From: Arushi Singhal @ 2017-04-01 16:13 UTC (permalink / raw)
  To: pablo
  Cc: kadlec, davem, kuznet, jmorris, yoshfuji, kaber, netfilter-devel,
	coreteam, netdev, linux-kernel, Arushi Singhal

Simplify NULL comparisons to follow kernel coding style.

Arushi Singhal (2):
  ipv4: netfilter: Simplify NULL comparisons
  ipv6: netfilter: Simplify NULL comparisons

 net/ipv4/netfilter/arp_tables.c                |  3 +--
 net/ipv4/netfilter/arptable_filter.c           |  2 +-
 net/ipv4/netfilter/ipt_CLUSTERIP.c             |  2 +-
 net/ipv4/netfilter/ipt_SYNPROXY.c              | 16 ++++++++--------
 net/ipv4/netfilter/iptable_filter.c            |  2 +-
 net/ipv4/netfilter/iptable_mangle.c            |  2 +-
 net/ipv4/netfilter/iptable_nat.c               |  2 +-
 net/ipv4/netfilter/iptable_raw.c               |  2 +-
 net/ipv4/netfilter/iptable_security.c          |  2 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |  4 ++--
 net/ipv4/netfilter/nf_conntrack_proto_icmp.c   |  4 ++--
 net/ipv4/netfilter/nf_dup_ipv4.c               |  2 +-
 net/ipv4/netfilter/nf_log_arp.c                |  4 ++--
 net/ipv4/netfilter/nf_log_ipv4.c               | 10 +++++-----
 net/ipv4/netfilter/nf_nat_snmp_basic.c         | 22 +++++++++++-----------
 net/ipv4/netfilter/nf_reject_ipv4.c            |  2 +-
 net/ipv4/netfilter/nf_socket_ipv4.c            |  8 ++++----
 net/ipv4/netfilter/nf_tables_arp.c             |  2 +-
 net/ipv4/netfilter/nf_tables_ipv4.c            |  2 +-
 net/ipv4/netfilter/nft_dup_ipv4.c              |  2 +-
 net/ipv6/netfilter/ip6t_SYNPROXY.c             | 16 ++++++++--------
 net/ipv6/netfilter/ip6t_ipv6header.c           |  2 +-
 net/ipv6/netfilter/ip6table_filter.c           |  2 +-
 net/ipv6/netfilter/ip6table_mangle.c           |  2 +-
 net/ipv6/netfilter/ip6table_nat.c              |  2 +-
 net/ipv6/netfilter/ip6table_raw.c              |  2 +-
 net/ipv6/netfilter/ip6table_security.c         |  2 +-
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c |  2 +-
 net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c |  4 ++--
 net/ipv6/netfilter/nf_conntrack_reasm.c        | 12 ++++++------
 net/ipv6/netfilter/nf_dup_ipv6.c               |  2 +-
 net/ipv6/netfilter/nf_log_ipv6.c               | 12 ++++++------
 net/ipv6/netfilter/nf_reject_ipv6.c            |  4 ++--
 net/ipv6/netfilter/nf_socket_ipv6.c            |  8 ++++----
 net/ipv6/netfilter/nf_tables_ipv6.c            |  2 +-
 net/ipv6/netfilter/nft_dup_ipv6.c              |  2 +-
 36 files changed, 85 insertions(+), 86 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ipv4: netfilter: Simplify NULL comparisons
  2017-04-01 16:13 [PATCH 0/2] Simplify NULL comparisons Arushi Singhal
@ 2017-04-01 16:13 ` Arushi Singhal
  2017-04-01 16:13 ` [PATCH 2/2] ipv6: " Arushi Singhal
  1 sibling, 0 replies; 4+ messages in thread
From: Arushi Singhal @ 2017-04-01 16:13 UTC (permalink / raw)
  To: pablo
  Cc: kadlec, davem, kuznet, jmorris, yoshfuji, kaber, netfilter-devel,
	coreteam, netdev, linux-kernel, Arushi Singhal

Remove instances of explicit NULL comparisons for code compaction.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
 net/ipv4/netfilter/arp_tables.c                |  3 +--
 net/ipv4/netfilter/arptable_filter.c           |  2 +-
 net/ipv4/netfilter/ipt_CLUSTERIP.c             |  2 +-
 net/ipv4/netfilter/ipt_SYNPROXY.c              | 16 ++++++++--------
 net/ipv4/netfilter/iptable_filter.c            |  2 +-
 net/ipv4/netfilter/iptable_mangle.c            |  2 +-
 net/ipv4/netfilter/iptable_nat.c               |  2 +-
 net/ipv4/netfilter/iptable_raw.c               |  2 +-
 net/ipv4/netfilter/iptable_security.c          |  2 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |  4 ++--
 net/ipv4/netfilter/nf_conntrack_proto_icmp.c   |  4 ++--
 net/ipv4/netfilter/nf_dup_ipv4.c               |  2 +-
 net/ipv4/netfilter/nf_log_arp.c                |  4 ++--
 net/ipv4/netfilter/nf_log_ipv4.c               | 10 +++++-----
 net/ipv4/netfilter/nf_nat_snmp_basic.c         | 22 +++++++++++-----------
 net/ipv4/netfilter/nf_reject_ipv4.c            |  2 +-
 net/ipv4/netfilter/nf_socket_ipv4.c            |  8 ++++----
 net/ipv4/netfilter/nf_tables_arp.c             |  2 +-
 net/ipv4/netfilter/nf_tables_ipv4.c            |  2 +-
 net/ipv4/netfilter/nft_dup_ipv4.c              |  2 +-
 20 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 6241a81fd7f5..7062ec86e3d7 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -652,8 +652,7 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
 	 */
 	countersize = sizeof(struct xt_counters) * private->number;
 	counters = vzalloc(countersize);
-
-	if (counters == NULL)
+	if (!counters)
 		return ERR_PTR(-ENOMEM);
 
 	get_counters(private, counters);
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
index 8f8713b4388f..1e44006215d1 100644
--- a/net/ipv4/netfilter/arptable_filter.c
+++ b/net/ipv4/netfilter/arptable_filter.c
@@ -47,7 +47,7 @@ static int __net_init arptable_filter_table_init(struct net *net)
 		return 0;
 
 	repl = arpt_alloc_initial_table(&packet_filter);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	err = arpt_register_table(net, &packet_filter, repl, arpfilter_ops,
 				  &net->ipv4.arptable_filter);
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 52f26459efc3..559a783d5b3f 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -328,7 +328,7 @@ clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par)
 	 * that the ->target() function isn't called after ->destroy() */
 
 	ct = nf_ct_get(skb, &ctinfo);
-	if (ct == NULL)
+	if (!ct)
 		return NF_DROP;
 
 	/* special case: ICMP error handling. conntrack distinguishes between
diff --git a/net/ipv4/netfilter/ipt_SYNPROXY.c b/net/ipv4/netfilter/ipt_SYNPROXY.c
index 3240a2614e82..10c970e32d5e 100644
--- a/net/ipv4/netfilter/ipt_SYNPROXY.c
+++ b/net/ipv4/netfilter/ipt_SYNPROXY.c
@@ -84,7 +84,7 @@ synproxy_send_client_synack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -126,7 +126,7 @@ synproxy_send_server_syn(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -171,7 +171,7 @@ synproxy_send_server_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -209,7 +209,7 @@ synproxy_send_client_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -271,7 +271,7 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 		return NF_DROP;
 
 	th = skb_header_pointer(skb, par->thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	if (!synproxy_parse_options(skb, par->thoff, th, &opts))
@@ -319,11 +319,11 @@ static unsigned int ipv4_synproxy_hook(void *priv,
 	unsigned int thoff;
 
 	ct = nf_ct_get(skb, &ctinfo);
-	if (ct == NULL)
+	if (!ct)
 		return NF_ACCEPT;
 
 	synproxy = nfct_synproxy(ct);
-	if (synproxy == NULL)
+	if (!synproxy)
 		return NF_ACCEPT;
 
 	if (nf_is_loopback_packet(skb))
@@ -331,7 +331,7 @@ static unsigned int ipv4_synproxy_hook(void *priv,
 
 	thoff = ip_hdrlen(skb);
 	th = skb_header_pointer(skb, thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	state = &ct->proto.tcp;
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index 7667f223d7f8..83983c7c156d 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -62,7 +62,7 @@ static int __net_init iptable_filter_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_filter);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	/* Entry 1 is the FORWARD hook */
 	((struct ipt_standard *)repl->entries)[1].target.verdict =
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index aebdb337fd7e..64a6d0c531d7 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -100,7 +100,7 @@ static int __net_init iptable_mangle_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_mangler);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &packet_mangler, repl, mangle_ops,
 				 &net->ipv4.iptable_mangle);
diff --git a/net/ipv4/netfilter/iptable_nat.c b/net/ipv4/netfilter/iptable_nat.c
index 138a24bc76ad..b7c9317fbae0 100644
--- a/net/ipv4/netfilter/iptable_nat.c
+++ b/net/ipv4/netfilter/iptable_nat.c
@@ -107,7 +107,7 @@ static int __net_init iptable_nat_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&nf_nat_ipv4_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &nf_nat_ipv4_table, repl,
 				 nf_nat_ipv4_ops, &net->ipv4.nat_table);
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index 2642ecd2645c..691c807b8afa 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -46,7 +46,7 @@ static int __net_init iptable_raw_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_raw);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &packet_raw, repl, rawtable_ops,
 				 &net->ipv4.iptable_raw);
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c
index ff226596e4b5..578de5ca922a 100644
--- a/net/ipv4/netfilter/iptable_security.c
+++ b/net/ipv4/netfilter/iptable_security.c
@@ -63,7 +63,7 @@ static int __net_init iptable_security_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&security_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &security_table, repl, sectbl_ops,
 				 &net->ipv4.iptable_security);
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 2e14ed11a35c..670b65947e54 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -45,7 +45,7 @@ static bool ipv4_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff,
 	__be32 _addrs[2];
 	ap = skb_header_pointer(skb, nhoff + offsetof(struct iphdr, saddr),
 				sizeof(u_int32_t) * 2, _addrs);
-	if (ap == NULL)
+	if (!ap)
 		return false;
 
 	tuple->src.u3.ip = ap[0];
@@ -77,7 +77,7 @@ static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
 	struct iphdr _iph;
 
 	iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
-	if (iph == NULL)
+	if (!iph)
 		return -NF_ACCEPT;
 
 	/* Conntrack defragments packets, we might still see fragments
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index 73c591d8a9a8..fc4b89f23a96 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -36,7 +36,7 @@ static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
 	struct icmphdr _hdr;
 
 	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
-	if (hp == NULL)
+	if (!hp)
 		return false;
 
 	tuple->dst.u.icmp.type = hp->type;
@@ -187,7 +187,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl,
 
 	/* Not enough header? */
 	icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
-	if (icmph == NULL) {
+	if (!icmph) {
 		if (LOG_INVALID(net, IPPROTO_ICMP))
 			nf_log_packet(net, PF_INET, 0, skb, NULL, NULL,
 				      NULL, "nf_ct_icmp: short packet ");
diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index f0dbff05fc28..1c95300b5a8b 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -63,7 +63,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
 	 * happened. The copy should be independently delivered to the gateway.
 	 */
 	skb = pskb_copy(skb, GFP_ATOMIC);
-	if (skb == NULL)
+	if (!skb)
 		return;
 
 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
diff --git a/net/ipv4/netfilter/nf_log_arp.c b/net/ipv4/netfilter/nf_log_arp.c
index 2f3895ddc275..88104f102b9e 100644
--- a/net/ipv4/netfilter/nf_log_arp.c
+++ b/net/ipv4/netfilter/nf_log_arp.c
@@ -52,7 +52,7 @@ static void dump_arp_packet(struct nf_log_buf *m,
 	struct arppayload _arpp;
 
 	ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
-	if (ah == NULL) {
+	if (!ah) {
 		nf_log_buf_add(m, "TRUNCATED");
 		return;
 	}
@@ -68,7 +68,7 @@ static void dump_arp_packet(struct nf_log_buf *m,
 		return;
 
 	ap = skb_header_pointer(skb, sizeof(_arph), sizeof(_arpp), &_arpp);
-	if (ap == NULL) {
+	if (!ap) {
 		nf_log_buf_add(m, " INCOMPLETE [%zu bytes]",
 			       skb->len - sizeof(_arph));
 		return;
diff --git a/net/ipv4/netfilter/nf_log_ipv4.c b/net/ipv4/netfilter/nf_log_ipv4.c
index c83a9963269b..9099972bcdae 100644
--- a/net/ipv4/netfilter/nf_log_ipv4.c
+++ b/net/ipv4/netfilter/nf_log_ipv4.c
@@ -49,7 +49,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		logflags = NF_LOG_DEFAULT_MASK;
 
 	ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
-	if (ih == NULL) {
+	if (!ih) {
 		nf_log_buf_add(m, "TRUNCATED");
 		return;
 	}
@@ -85,7 +85,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		optsize = ih->ihl * 4 - sizeof(struct iphdr);
 		op = skb_header_pointer(skb, iphoff+sizeof(_iph),
 					optsize, _opt);
-		if (op == NULL) {
+		if (!op) {
 			nf_log_buf_add(m, "TRUNCATED");
 			return;
 		}
@@ -141,7 +141,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		ich = skb_header_pointer(skb, iphoff + ih->ihl * 4,
 					 sizeof(_icmph), &_icmph);
-		if (ich == NULL) {
+		if (!ich) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
@@ -211,7 +211,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		ah = skb_header_pointer(skb, iphoff+ih->ihl*4,
 					sizeof(_ahdr), &_ahdr);
-		if (ah == NULL) {
+		if (!ah) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
@@ -234,7 +234,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		eh = skb_header_pointer(skb, iphoff+ih->ihl*4,
 					sizeof(_esph), &_esph);
-		if (eh == NULL) {
+		if (!eh) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index c9b52c361da2..890960552c97 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -273,7 +273,7 @@ static unsigned char asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc)
 {
 	unsigned char ch;
 
-	if (eoc == NULL) {
+	if (!eoc) {
 		if (!asn1_octet_decode(ctx, &ch))
 			return 0;
 
@@ -401,7 +401,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
 	*len = 0;
 
 	*octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
-	if (*octets == NULL)
+	if (!*octets)
 		return 0;
 
 	ptr = *octets;
@@ -449,7 +449,7 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
 		return 0;
 
 	*oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC);
-	if (*oid == NULL)
+	if (!*oid)
 		return 0;
 
 	optr = *oid;
@@ -721,7 +721,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -734,7 +734,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(p);
 			kfree(id);
 			return 0;
@@ -748,7 +748,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 	case SNMP_ENDOFMIBVIEW:
 		len = 0;
 		*obj = kmalloc(sizeof(struct snmp_object), GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -766,7 +766,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 		}
 		len *= sizeof(unsigned long);
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(lp);
 			kfree(id);
 			return 0;
@@ -785,7 +785,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(p);
 			kfree(id);
 			return 0;
@@ -802,7 +802,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -1045,7 +1045,7 @@ static int snmp_parse_mangle(unsigned char *msg,
 		return 0;
 	if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
 		return 0;
-	if (!asn1_uint_decode (&ctx, end, &vers))
+	if (!asn1_uint_decode(&ctx, end, &vers))
 		return 0;
 	if (debug > 1)
 		pr_debug("bsalg: snmp version: %u\n", vers + 1);
@@ -1055,7 +1055,7 @@ static int snmp_parse_mangle(unsigned char *msg,
 	/*
 	 * Community.
 	 */
-	if (!asn1_header_decode (&ctx, &end, &cls, &con, &tag))
+	if (!asn1_header_decode(&ctx, &end, &cls, &con, &tag))
 		return 0;
 	if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OTS)
 		return 0;
diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
index 146d86105183..ea1d860c0040 100644
--- a/net/ipv4/netfilter/nf_reject_ipv4.c
+++ b/net/ipv4/netfilter/nf_reject_ipv4.c
@@ -29,7 +29,7 @@ const struct tcphdr *nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,
 
 	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
 				 sizeof(struct tcphdr), _oth);
-	if (oth == NULL)
+	if (!oth)
 		return NULL;
 
 	/* No RST for RST. */
diff --git a/net/ipv4/netfilter/nf_socket_ipv4.c b/net/ipv4/netfilter/nf_socket_ipv4.c
index a83d558e1aae..777888e742f7 100644
--- a/net/ipv4/netfilter/nf_socket_ipv4.c
+++ b/net/ipv4/netfilter/nf_socket_ipv4.c
@@ -32,7 +32,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 
 	icmph = skb_header_pointer(skb, outside_hdrlen,
 				   sizeof(_icmph), &_icmph);
-	if (icmph == NULL)
+	if (!icmph)
 		return 1;
 
 	switch (icmph->type) {
@@ -49,7 +49,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 	inside_iph = skb_header_pointer(skb, outside_hdrlen +
 					sizeof(struct icmphdr),
 					sizeof(_inside_iph), &_inside_iph);
-	if (inside_iph == NULL)
+	if (!inside_iph)
 		return 1;
 
 	if (inside_iph->protocol != IPPROTO_TCP &&
@@ -60,7 +60,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 				   sizeof(struct icmphdr) +
 				   (inside_iph->ihl << 2),
 				   sizeof(_ports), &_ports);
-	if (ports == NULL)
+	if (!ports)
 		return 1;
 
 	/* the inside IP packet is the one quoted from our side, thus
@@ -112,7 +112,7 @@ struct sock *nf_sk_lookup_slow_v4(struct net *net, const struct sk_buff *skb,
 
 		hp = skb_header_pointer(skb, ip_hdrlen(skb),
 					sizeof(_hdr), &_hdr);
-		if (hp == NULL)
+		if (!hp)
 			return NULL;
 
 		protocol = iph->protocol;
diff --git a/net/ipv4/netfilter/nf_tables_arp.c b/net/ipv4/netfilter/nf_tables_arp.c
index 805c8ddfe860..3634f0df42f7 100644
--- a/net/ipv4/netfilter/nf_tables_arp.c
+++ b/net/ipv4/netfilter/nf_tables_arp.c
@@ -41,7 +41,7 @@ static struct nft_af_info nft_af_arp __read_mostly = {
 static int nf_tables_arp_init_net(struct net *net)
 {
 	net->nft.arp = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
-	if (net->nft.arp== NULL)
+	if (!net->nft.arp)
 		return -ENOMEM;
 
 	memcpy(net->nft.arp, &nft_af_arp, sizeof(nft_af_arp));
diff --git a/net/ipv4/netfilter/nf_tables_ipv4.c b/net/ipv4/netfilter/nf_tables_ipv4.c
index 2840a29b2e04..bedbd62ab755 100644
--- a/net/ipv4/netfilter/nf_tables_ipv4.c
+++ b/net/ipv4/netfilter/nf_tables_ipv4.c
@@ -62,7 +62,7 @@ EXPORT_SYMBOL_GPL(nft_af_ipv4);
 static int nf_tables_ipv4_init_net(struct net *net)
 {
 	net->nft.ipv4 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
-	if (net->nft.ipv4 == NULL)
+	if (!net->nft.ipv4)
 		return -ENOMEM;
 
 	memcpy(net->nft.ipv4, &nft_af_ipv4, sizeof(nft_af_ipv4));
diff --git a/net/ipv4/netfilter/nft_dup_ipv4.c b/net/ipv4/netfilter/nft_dup_ipv4.c
index 0af3d8df70dd..362c4eaa8187 100644
--- a/net/ipv4/netfilter/nft_dup_ipv4.c
+++ b/net/ipv4/netfilter/nft_dup_ipv4.c
@@ -40,7 +40,7 @@ static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
 	struct nft_dup_ipv4 *priv = nft_expr_priv(expr);
 	int err;
 
-	if (tb[NFTA_DUP_SREG_ADDR] == NULL)
+	if (!tb[NFTA_DUP_SREG_ADDR])
 		return -EINVAL;
 
 	priv->sreg_addr = nft_parse_register(tb[NFTA_DUP_SREG_ADDR]);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ipv6: netfilter: Simplify NULL comparisons
  2017-04-01 16:13 [PATCH 0/2] Simplify NULL comparisons Arushi Singhal
  2017-04-01 16:13 ` [PATCH 1/2] ipv4: netfilter: " Arushi Singhal
@ 2017-04-01 16:13 ` Arushi Singhal
  1 sibling, 0 replies; 4+ messages in thread
From: Arushi Singhal @ 2017-04-01 16:13 UTC (permalink / raw)
  To: pablo
  Cc: kadlec, davem, kuznet, jmorris, yoshfuji, kaber, netfilter-devel,
	coreteam, netdev, linux-kernel, Arushi Singhal

Remove instances of explicit NULL comparisons for code compaction.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
 net/ipv6/netfilter/ip6t_SYNPROXY.c             | 16 ++++++++--------
 net/ipv6/netfilter/ip6t_ipv6header.c           |  2 +-
 net/ipv6/netfilter/ip6table_filter.c           |  2 +-
 net/ipv6/netfilter/ip6table_mangle.c           |  2 +-
 net/ipv6/netfilter/ip6table_nat.c              |  2 +-
 net/ipv6/netfilter/ip6table_raw.c              |  2 +-
 net/ipv6/netfilter/ip6table_security.c         |  2 +-
 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c |  2 +-
 net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c |  4 ++--
 net/ipv6/netfilter/nf_conntrack_reasm.c        | 12 ++++++------
 net/ipv6/netfilter/nf_dup_ipv6.c               |  2 +-
 net/ipv6/netfilter/nf_log_ipv6.c               | 12 ++++++------
 net/ipv6/netfilter/nf_reject_ipv6.c            |  4 ++--
 net/ipv6/netfilter/nf_socket_ipv6.c            |  8 ++++----
 net/ipv6/netfilter/nf_tables_ipv6.c            |  2 +-
 net/ipv6/netfilter/nft_dup_ipv6.c              |  2 +-
 16 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/net/ipv6/netfilter/ip6t_SYNPROXY.c b/net/ipv6/netfilter/ip6t_SYNPROXY.c
index 4ef1ddd4bbbd..e0fa78085ad7 100644
--- a/net/ipv6/netfilter/ip6t_SYNPROXY.c
+++ b/net/ipv6/netfilter/ip6t_SYNPROXY.c
@@ -98,7 +98,7 @@ synproxy_send_client_synack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -140,7 +140,7 @@ synproxy_send_server_syn(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -185,7 +185,7 @@ synproxy_send_server_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -223,7 +223,7 @@ synproxy_send_client_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -285,7 +285,7 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 		return NF_DROP;
 
 	th = skb_header_pointer(skb, par->thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	if (!synproxy_parse_options(skb, par->thoff, th, &opts))
@@ -335,11 +335,11 @@ static unsigned int ipv6_synproxy_hook(void *priv,
 	int thoff;
 
 	ct = nf_ct_get(skb, &ctinfo);
-	if (ct == NULL)
+	if (!ct)
 		return NF_ACCEPT;
 
 	synproxy = nfct_synproxy(ct);
-	if (synproxy == NULL)
+	if (!synproxy)
 		return NF_ACCEPT;
 
 	if (nf_is_loopback_packet(skb))
@@ -352,7 +352,7 @@ static unsigned int ipv6_synproxy_hook(void *priv,
 		return NF_ACCEPT;
 
 	th = skb_header_pointer(skb, thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	state = &ct->proto.tcp;
diff --git a/net/ipv6/netfilter/ip6t_ipv6header.c b/net/ipv6/netfilter/ip6t_ipv6header.c
index 8b147440fbdc..c53ce6928130 100644
--- a/net/ipv6/netfilter/ip6t_ipv6header.c
+++ b/net/ipv6/netfilter/ip6t_ipv6header.c
@@ -65,7 +65,7 @@ ipv6header_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 		}
 
 		hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
-		BUG_ON(hp == NULL);
+		BUG_ON(!hp);
 
 		/* Calculate the header length */
 		if (nexthdr == NEXTHDR_FRAGMENT)
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
index 1343077dde93..5c645fbf62ec 100644
--- a/net/ipv6/netfilter/ip6table_filter.c
+++ b/net/ipv6/netfilter/ip6table_filter.c
@@ -56,7 +56,7 @@ static int __net_init ip6table_filter_table_init(struct net *net)
 		return 0;
 
 	repl = ip6t_alloc_initial_table(&packet_filter);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	/* Entry 1 is the FORWARD hook */
 	((struct ip6t_standard *)repl->entries)[1].target.verdict =
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c
index 2b1a9dcdbcb3..7d7ed25ff568 100644
--- a/net/ipv6/netfilter/ip6table_mangle.c
+++ b/net/ipv6/netfilter/ip6table_mangle.c
@@ -96,7 +96,7 @@ static int __net_init ip6table_mangle_table_init(struct net *net)
 		return 0;
 
 	repl = ip6t_alloc_initial_table(&packet_mangler);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ip6t_register_table(net, &packet_mangler, repl, mangle_ops,
 				  &net->ipv6.ip6table_mangle);
diff --git a/net/ipv6/netfilter/ip6table_nat.c b/net/ipv6/netfilter/ip6table_nat.c
index 7d2bd940291f..ec7f82a65a33 100644
--- a/net/ipv6/netfilter/ip6table_nat.c
+++ b/net/ipv6/netfilter/ip6table_nat.c
@@ -109,7 +109,7 @@ static int __net_init ip6table_nat_table_init(struct net *net)
 		return 0;
 
 	repl = ip6t_alloc_initial_table(&nf_nat_ipv6_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ip6t_register_table(net, &nf_nat_ipv6_table, repl,
 				  nf_nat_ipv6_ops, &net->ipv6.ip6table_nat);
diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c
index d4bc56443dc1..39d61bc9f888 100644
--- a/net/ipv6/netfilter/ip6table_raw.c
+++ b/net/ipv6/netfilter/ip6table_raw.c
@@ -39,7 +39,7 @@ static int __net_init ip6table_raw_table_init(struct net *net)
 		return 0;
 
 	repl = ip6t_alloc_initial_table(&packet_raw);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ip6t_register_table(net, &packet_raw, repl, rawtable_ops,
 				  &net->ipv6.ip6table_raw);
diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c
index cf26ccb04056..fad7d03e2553 100644
--- a/net/ipv6/netfilter/ip6table_security.c
+++ b/net/ipv6/netfilter/ip6table_security.c
@@ -56,7 +56,7 @@ static int __net_init ip6table_security_table_init(struct net *net)
 		return 0;
 
 	repl = ip6t_alloc_initial_table(&security_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ip6t_register_table(net, &security_table, repl, sectbl_ops,
 				  &net->ipv6.ip6table_security);
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index 4e3402486833..b88b98105c61 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -49,7 +49,7 @@ static bool ipv6_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff,
 
 	ap = skb_header_pointer(skb, nhoff + offsetof(struct ipv6hdr, saddr),
 				sizeof(_addrs), _addrs);
-	if (ap == NULL)
+	if (!ap)
 		return false;
 
 	memcpy(tuple->src.u3.ip6, ap, sizeof(tuple->src.u3.ip6));
diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
index d2c2ccbfbe72..46892d085c25 100644
--- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
@@ -43,7 +43,7 @@ static bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
 	struct icmp6hdr _hdr;
 
 	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
-	if (hp == NULL)
+	if (!hp)
 		return false;
 	tuple->dst.u.icmp.type = hp->icmp6_type;
 	tuple->src.u.icmp.id = hp->icmp6_identifier;
@@ -203,7 +203,7 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl,
 	int type;
 
 	icmp6h = skb_header_pointer(skb, dataoff, sizeof(_ih), &_ih);
-	if (icmp6h == NULL) {
+	if (!icmp6h) {
 		if (LOG_INVALID(net, IPPROTO_ICMPV6))
 			nf_log_packet(net, PF_INET6, 0, skb, NULL, NULL, NULL,
 			      "nf_ct_icmpv6: short packet ");
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 986d4ca38832..042bcbb11f00 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -102,7 +102,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
 	if (!net_eq(net, &init_net)) {
 		table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
 				GFP_KERNEL);
-		if (table == NULL)
+		if (!table)
 			goto err_alloc;
 
 		table[0].data = &net->nf_frag.frags.timeout;
@@ -114,7 +114,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
 	}
 
 	hdr = register_net_sysctl(net, "net/netfilter", table);
-	if (hdr == NULL)
+	if (!hdr)
 		goto err_reg;
 
 	net->nf_frag.sysctl.frags_hdr = hdr;
@@ -279,7 +279,7 @@ static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb,
 		goto err;
 
 	/* Point into the IP datagram 'data' part. */
-	if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) {
+	if (!pskb_pull(skb, (u8 *)(fhdr + 1) - skb->data)) {
 		pr_debug("queue: message is too short.\n");
 		goto err;
 	}
@@ -379,7 +379,7 @@ nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *prev,  struct net_devic
 
 	inet_frag_kill(&fq->q, &nf_frags);
 
-	WARN_ON(head == NULL);
+	WARN_ON(!head);
 	WARN_ON(NFCT_FRAG6_CB(head)->offset != 0);
 
 	ecn = ip_frag_ecn_table[fq->ecn];
@@ -408,7 +408,7 @@ nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *prev,  struct net_devic
 		int i, plen = 0;
 
 		clone = alloc_skb(0, GFP_ATOMIC);
-		if (clone == NULL)
+		if (!clone)
 			return false;
 
 		clone->next = head->next;
@@ -592,7 +592,7 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)
 	skb_orphan(skb);
 	fq = fq_find(net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,
 		     skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
-	if (fq == NULL) {
+	if (!fq) {
 		pr_debug("Can't find and can't create new queue\n");
 		return -ENOMEM;
 	}
diff --git a/net/ipv6/netfilter/nf_dup_ipv6.c b/net/ipv6/netfilter/nf_dup_ipv6.c
index 888ecd106e5f..b77896b2a9bd 100644
--- a/net/ipv6/netfilter/nf_dup_ipv6.c
+++ b/net/ipv6/netfilter/nf_dup_ipv6.c
@@ -53,7 +53,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
 	if (this_cpu_read(nf_skb_duplicated))
 		return;
 	skb = pskb_copy(skb, GFP_ATOMIC);
-	if (skb == NULL)
+	if (!skb)
 		return;
 
 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
diff --git a/net/ipv6/netfilter/nf_log_ipv6.c b/net/ipv6/netfilter/nf_log_ipv6.c
index 97c724224da7..d8a88b81893b 100644
--- a/net/ipv6/netfilter/nf_log_ipv6.c
+++ b/net/ipv6/netfilter/nf_log_ipv6.c
@@ -55,7 +55,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 		logflags = NF_LOG_DEFAULT_MASK;
 
 	ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
-	if (ih == NULL) {
+	if (!ih) {
 		nf_log_buf_add(m, "TRUNCATED");
 		return;
 	}
@@ -78,7 +78,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 		const struct ipv6_opt_hdr *hp;
 
 		hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
-		if (hp == NULL) {
+		if (!hp) {
 			nf_log_buf_add(m, "TRUNCATED");
 			return;
 		}
@@ -95,7 +95,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 			nf_log_buf_add(m, "FRAG:");
 			fh = skb_header_pointer(skb, ptr, sizeof(_fhdr),
 						&_fhdr);
-			if (fh == NULL) {
+			if (!fh) {
 				nf_log_buf_add(m, "TRUNCATED ");
 				return;
 			}
@@ -143,7 +143,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 
 				ah = skb_header_pointer(skb, ptr, sizeof(_ahdr),
 							&_ahdr);
-				if (ah == NULL) {
+				if (!ah) {
 					/*
 					 * Max length: 26 "INCOMPLETE [65535
 					 *  bytes] )"
@@ -178,7 +178,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 				 */
 				eh = skb_header_pointer(skb, ptr, sizeof(_esph),
 							&_esph);
-				if (eh == NULL) {
+				if (!eh) {
 					nf_log_buf_add(m, "INCOMPLETE [%u bytes] )",
 						       skb->len - ptr);
 					return;
@@ -224,7 +224,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
 
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h);
-		if (ic == NULL) {
+		if (!ic) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - ptr);
 			return;
diff --git a/net/ipv6/netfilter/nf_reject_ipv6.c b/net/ipv6/netfilter/nf_reject_ipv6.c
index eedee5d108d9..c97ed15df5c2 100644
--- a/net/ipv6/netfilter/nf_reject_ipv6.c
+++ b/net/ipv6/netfilter/nf_reject_ipv6.c
@@ -44,7 +44,7 @@ const struct tcphdr *nf_reject_ip6_tcphdr_get(struct sk_buff *oldskb,
 
 	otcph = skb_header_pointer(oldskb, tcphoff, sizeof(struct tcphdr),
 				   otcph);
-	if (otcph == NULL)
+	if (!otcph)
 		return NULL;
 
 	/* No RST for RST. */
@@ -241,7 +241,7 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,
 	if (!reject6_csum_ok(skb_in, hooknum))
 		return;
 
-	if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL)
+	if (hooknum == NF_INET_LOCAL_OUT && !skb_in->dev)
 		skb_in->dev = net->loopback_dev;
 
 	icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0);
diff --git a/net/ipv6/netfilter/nf_socket_ipv6.c b/net/ipv6/netfilter/nf_socket_ipv6.c
index ebb2bf84232a..e7e85795edec 100644
--- a/net/ipv6/netfilter/nf_socket_ipv6.c
+++ b/net/ipv6/netfilter/nf_socket_ipv6.c
@@ -41,7 +41,7 @@ extract_icmp6_fields(const struct sk_buff *skb,
 
 	icmph = skb_header_pointer(skb, outside_hdrlen,
 				   sizeof(_icmph), &_icmph);
-	if (icmph == NULL)
+	if (!icmph)
 		return 1;
 
 	if (icmph->icmp6_type & ICMPV6_INFOMSG_MASK)
@@ -49,7 +49,7 @@ extract_icmp6_fields(const struct sk_buff *skb,
 
 	inside_iph = skb_header_pointer(skb, outside_hdrlen + sizeof(_icmph),
 					sizeof(*ipv6_var), ipv6_var);
-	if (inside_iph == NULL)
+	if (!inside_iph)
 		return 1;
 	inside_nexthdr = inside_iph->nexthdr;
 
@@ -65,7 +65,7 @@ extract_icmp6_fields(const struct sk_buff *skb,
 
 	ports = skb_header_pointer(skb, inside_hdrlen,
 				   sizeof(_ports), &_ports);
-	if (ports == NULL)
+	if (!ports)
 		return 1;
 
 	/* the inside IP packet is the one quoted from our side, thus
@@ -119,7 +119,7 @@ struct sock *nf_sk_lookup_slow_v6(struct net *net, const struct sk_buff *skb,
 		struct udphdr _hdr, *hp;
 
 		hp = skb_header_pointer(skb, thoff, sizeof(_hdr), &_hdr);
-		if (hp == NULL)
+		if (!hp)
 			return NULL;
 
 		saddr = &iph->saddr;
diff --git a/net/ipv6/netfilter/nf_tables_ipv6.c b/net/ipv6/netfilter/nf_tables_ipv6.c
index d6e4ba5de916..7a3d1b5017a1 100644
--- a/net/ipv6/netfilter/nf_tables_ipv6.c
+++ b/net/ipv6/netfilter/nf_tables_ipv6.c
@@ -59,7 +59,7 @@ EXPORT_SYMBOL_GPL(nft_af_ipv6);
 static int nf_tables_ipv6_init_net(struct net *net)
 {
 	net->nft.ipv6 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
-	if (net->nft.ipv6 == NULL)
+	if (!net->nft.ipv6)
 		return -ENOMEM;
 
 	memcpy(net->nft.ipv6, &nft_af_ipv6, sizeof(nft_af_ipv6));
diff --git a/net/ipv6/netfilter/nft_dup_ipv6.c b/net/ipv6/netfilter/nft_dup_ipv6.c
index d8b5b60b7d53..2badafe43db9 100644
--- a/net/ipv6/netfilter/nft_dup_ipv6.c
+++ b/net/ipv6/netfilter/nft_dup_ipv6.c
@@ -38,7 +38,7 @@ static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
 	struct nft_dup_ipv6 *priv = nft_expr_priv(expr);
 	int err;
 
-	if (tb[NFTA_DUP_SREG_ADDR] == NULL)
+	if (!tb[NFTA_DUP_SREG_ADDR])
 		return -EINVAL;
 
 	priv->sreg_addr = nft_parse_register(tb[NFTA_DUP_SREG_ADDR]);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ipv4: netfilter: Simplify NULL comparisons
@ 2017-04-02  5:31 Arushi Singhal
  0 siblings, 0 replies; 4+ messages in thread
From: Arushi Singhal @ 2017-04-02  5:31 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Arushi Singhal

Remove instances of explicit NULL comparisons for code compaction.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
 net/ipv4/netfilter/arp_tables.c                |  3 +--
 net/ipv4/netfilter/arptable_filter.c           |  2 +-
 net/ipv4/netfilter/ipt_CLUSTERIP.c             |  2 +-
 net/ipv4/netfilter/ipt_SYNPROXY.c              | 16 ++++++++--------
 net/ipv4/netfilter/iptable_filter.c            |  2 +-
 net/ipv4/netfilter/iptable_mangle.c            |  2 +-
 net/ipv4/netfilter/iptable_nat.c               |  2 +-
 net/ipv4/netfilter/iptable_raw.c               |  2 +-
 net/ipv4/netfilter/iptable_security.c          |  2 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |  4 ++--
 net/ipv4/netfilter/nf_conntrack_proto_icmp.c   |  4 ++--
 net/ipv4/netfilter/nf_dup_ipv4.c               |  2 +-
 net/ipv4/netfilter/nf_log_arp.c                |  4 ++--
 net/ipv4/netfilter/nf_log_ipv4.c               | 10 +++++-----
 net/ipv4/netfilter/nf_nat_snmp_basic.c         | 22 +++++++++++-----------
 net/ipv4/netfilter/nf_reject_ipv4.c            |  2 +-
 net/ipv4/netfilter/nf_socket_ipv4.c            |  8 ++++----
 net/ipv4/netfilter/nf_tables_arp.c             |  2 +-
 net/ipv4/netfilter/nf_tables_ipv4.c            |  2 +-
 net/ipv4/netfilter/nft_dup_ipv4.c              |  2 +-
 20 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 6241a81fd7f5..7062ec86e3d7 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -652,8 +652,7 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
 	 */
 	countersize = sizeof(struct xt_counters) * private->number;
 	counters = vzalloc(countersize);
-
-	if (counters == NULL)
+	if (!counters)
 		return ERR_PTR(-ENOMEM);
 
 	get_counters(private, counters);
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
index 8f8713b4388f..1e44006215d1 100644
--- a/net/ipv4/netfilter/arptable_filter.c
+++ b/net/ipv4/netfilter/arptable_filter.c
@@ -47,7 +47,7 @@ static int __net_init arptable_filter_table_init(struct net *net)
 		return 0;
 
 	repl = arpt_alloc_initial_table(&packet_filter);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	err = arpt_register_table(net, &packet_filter, repl, arpfilter_ops,
 				  &net->ipv4.arptable_filter);
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 52f26459efc3..559a783d5b3f 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -328,7 +328,7 @@ clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par)
 	 * that the ->target() function isn't called after ->destroy() */
 
 	ct = nf_ct_get(skb, &ctinfo);
-	if (ct == NULL)
+	if (!ct)
 		return NF_DROP;
 
 	/* special case: ICMP error handling. conntrack distinguishes between
diff --git a/net/ipv4/netfilter/ipt_SYNPROXY.c b/net/ipv4/netfilter/ipt_SYNPROXY.c
index 3240a2614e82..10c970e32d5e 100644
--- a/net/ipv4/netfilter/ipt_SYNPROXY.c
+++ b/net/ipv4/netfilter/ipt_SYNPROXY.c
@@ -84,7 +84,7 @@ synproxy_send_client_synack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -126,7 +126,7 @@ synproxy_send_server_syn(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -171,7 +171,7 @@ synproxy_send_server_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -209,7 +209,7 @@ synproxy_send_client_ack(struct net *net,
 	tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
 	nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
 			 GFP_ATOMIC);
-	if (nskb == NULL)
+	if (!nskb)
 		return;
 	skb_reserve(nskb, MAX_TCP_HEADER);
 
@@ -271,7 +271,7 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 		return NF_DROP;
 
 	th = skb_header_pointer(skb, par->thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	if (!synproxy_parse_options(skb, par->thoff, th, &opts))
@@ -319,11 +319,11 @@ static unsigned int ipv4_synproxy_hook(void *priv,
 	unsigned int thoff;
 
 	ct = nf_ct_get(skb, &ctinfo);
-	if (ct == NULL)
+	if (!ct)
 		return NF_ACCEPT;
 
 	synproxy = nfct_synproxy(ct);
-	if (synproxy == NULL)
+	if (!synproxy)
 		return NF_ACCEPT;
 
 	if (nf_is_loopback_packet(skb))
@@ -331,7 +331,7 @@ static unsigned int ipv4_synproxy_hook(void *priv,
 
 	thoff = ip_hdrlen(skb);
 	th = skb_header_pointer(skb, thoff, sizeof(_th), &_th);
-	if (th == NULL)
+	if (!th)
 		return NF_DROP;
 
 	state = &ct->proto.tcp;
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index 7667f223d7f8..83983c7c156d 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -62,7 +62,7 @@ static int __net_init iptable_filter_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_filter);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	/* Entry 1 is the FORWARD hook */
 	((struct ipt_standard *)repl->entries)[1].target.verdict =
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index aebdb337fd7e..64a6d0c531d7 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -100,7 +100,7 @@ static int __net_init iptable_mangle_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_mangler);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &packet_mangler, repl, mangle_ops,
 				 &net->ipv4.iptable_mangle);
diff --git a/net/ipv4/netfilter/iptable_nat.c b/net/ipv4/netfilter/iptable_nat.c
index 138a24bc76ad..b7c9317fbae0 100644
--- a/net/ipv4/netfilter/iptable_nat.c
+++ b/net/ipv4/netfilter/iptable_nat.c
@@ -107,7 +107,7 @@ static int __net_init iptable_nat_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&nf_nat_ipv4_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &nf_nat_ipv4_table, repl,
 				 nf_nat_ipv4_ops, &net->ipv4.nat_table);
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index 2642ecd2645c..691c807b8afa 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -46,7 +46,7 @@ static int __net_init iptable_raw_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&packet_raw);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &packet_raw, repl, rawtable_ops,
 				 &net->ipv4.iptable_raw);
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c
index ff226596e4b5..578de5ca922a 100644
--- a/net/ipv4/netfilter/iptable_security.c
+++ b/net/ipv4/netfilter/iptable_security.c
@@ -63,7 +63,7 @@ static int __net_init iptable_security_table_init(struct net *net)
 		return 0;
 
 	repl = ipt_alloc_initial_table(&security_table);
-	if (repl == NULL)
+	if (!repl)
 		return -ENOMEM;
 	ret = ipt_register_table(net, &security_table, repl, sectbl_ops,
 				 &net->ipv4.iptable_security);
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 2e14ed11a35c..670b65947e54 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -45,7 +45,7 @@ static bool ipv4_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff,
 	__be32 _addrs[2];
 	ap = skb_header_pointer(skb, nhoff + offsetof(struct iphdr, saddr),
 				sizeof(u_int32_t) * 2, _addrs);
-	if (ap == NULL)
+	if (!ap)
 		return false;
 
 	tuple->src.u3.ip = ap[0];
@@ -77,7 +77,7 @@ static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
 	struct iphdr _iph;
 
 	iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
-	if (iph == NULL)
+	if (!iph)
 		return -NF_ACCEPT;
 
 	/* Conntrack defragments packets, we might still see fragments
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index 73c591d8a9a8..fc4b89f23a96 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -36,7 +36,7 @@ static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
 	struct icmphdr _hdr;
 
 	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
-	if (hp == NULL)
+	if (!hp)
 		return false;
 
 	tuple->dst.u.icmp.type = hp->type;
@@ -187,7 +187,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl,
 
 	/* Not enough header? */
 	icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
-	if (icmph == NULL) {
+	if (!icmph) {
 		if (LOG_INVALID(net, IPPROTO_ICMP))
 			nf_log_packet(net, PF_INET, 0, skb, NULL, NULL,
 				      NULL, "nf_ct_icmp: short packet ");
diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index f0dbff05fc28..1c95300b5a8b 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -63,7 +63,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
 	 * happened. The copy should be independently delivered to the gateway.
 	 */
 	skb = pskb_copy(skb, GFP_ATOMIC);
-	if (skb == NULL)
+	if (!skb)
 		return;
 
 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
diff --git a/net/ipv4/netfilter/nf_log_arp.c b/net/ipv4/netfilter/nf_log_arp.c
index 2f3895ddc275..88104f102b9e 100644
--- a/net/ipv4/netfilter/nf_log_arp.c
+++ b/net/ipv4/netfilter/nf_log_arp.c
@@ -52,7 +52,7 @@ static void dump_arp_packet(struct nf_log_buf *m,
 	struct arppayload _arpp;
 
 	ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
-	if (ah == NULL) {
+	if (!ah) {
 		nf_log_buf_add(m, "TRUNCATED");
 		return;
 	}
@@ -68,7 +68,7 @@ static void dump_arp_packet(struct nf_log_buf *m,
 		return;
 
 	ap = skb_header_pointer(skb, sizeof(_arph), sizeof(_arpp), &_arpp);
-	if (ap == NULL) {
+	if (!ap) {
 		nf_log_buf_add(m, " INCOMPLETE [%zu bytes]",
 			       skb->len - sizeof(_arph));
 		return;
diff --git a/net/ipv4/netfilter/nf_log_ipv4.c b/net/ipv4/netfilter/nf_log_ipv4.c
index c83a9963269b..9099972bcdae 100644
--- a/net/ipv4/netfilter/nf_log_ipv4.c
+++ b/net/ipv4/netfilter/nf_log_ipv4.c
@@ -49,7 +49,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		logflags = NF_LOG_DEFAULT_MASK;
 
 	ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
-	if (ih == NULL) {
+	if (!ih) {
 		nf_log_buf_add(m, "TRUNCATED");
 		return;
 	}
@@ -85,7 +85,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		optsize = ih->ihl * 4 - sizeof(struct iphdr);
 		op = skb_header_pointer(skb, iphoff+sizeof(_iph),
 					optsize, _opt);
-		if (op == NULL) {
+		if (!op) {
 			nf_log_buf_add(m, "TRUNCATED");
 			return;
 		}
@@ -141,7 +141,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		ich = skb_header_pointer(skb, iphoff + ih->ihl * 4,
 					 sizeof(_icmph), &_icmph);
-		if (ich == NULL) {
+		if (!ich) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
@@ -211,7 +211,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		ah = skb_header_pointer(skb, iphoff+ih->ihl*4,
 					sizeof(_ahdr), &_ahdr);
-		if (ah == NULL) {
+		if (!ah) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
@@ -234,7 +234,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
 		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
 		eh = skb_header_pointer(skb, iphoff+ih->ihl*4,
 					sizeof(_esph), &_esph);
-		if (eh == NULL) {
+		if (!eh) {
 			nf_log_buf_add(m, "INCOMPLETE [%u bytes] ",
 				       skb->len - iphoff - ih->ihl*4);
 			break;
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index c9b52c361da2..890960552c97 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -273,7 +273,7 @@ static unsigned char asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc)
 {
 	unsigned char ch;
 
-	if (eoc == NULL) {
+	if (!eoc) {
 		if (!asn1_octet_decode(ctx, &ch))
 			return 0;
 
@@ -401,7 +401,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
 	*len = 0;
 
 	*octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
-	if (*octets == NULL)
+	if (!*octets)
 		return 0;
 
 	ptr = *octets;
@@ -449,7 +449,7 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
 		return 0;
 
 	*oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC);
-	if (*oid == NULL)
+	if (!*oid)
 		return 0;
 
 	optr = *oid;
@@ -721,7 +721,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -734,7 +734,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(p);
 			kfree(id);
 			return 0;
@@ -748,7 +748,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 	case SNMP_ENDOFMIBVIEW:
 		len = 0;
 		*obj = kmalloc(sizeof(struct snmp_object), GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -766,7 +766,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 		}
 		len *= sizeof(unsigned long);
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(lp);
 			kfree(id);
 			return 0;
@@ -785,7 +785,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(p);
 			kfree(id);
 			return 0;
@@ -802,7 +802,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
 			return 0;
 		}
 		*obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
-		if (*obj == NULL) {
+		if (!*obj) {
 			kfree(id);
 			return 0;
 		}
@@ -1045,7 +1045,7 @@ static int snmp_parse_mangle(unsigned char *msg,
 		return 0;
 	if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_INT)
 		return 0;
-	if (!asn1_uint_decode (&ctx, end, &vers))
+	if (!asn1_uint_decode(&ctx, end, &vers))
 		return 0;
 	if (debug > 1)
 		pr_debug("bsalg: snmp version: %u\n", vers + 1);
@@ -1055,7 +1055,7 @@ static int snmp_parse_mangle(unsigned char *msg,
 	/*
 	 * Community.
 	 */
-	if (!asn1_header_decode (&ctx, &end, &cls, &con, &tag))
+	if (!asn1_header_decode(&ctx, &end, &cls, &con, &tag))
 		return 0;
 	if (cls != ASN1_UNI || con != ASN1_PRI || tag != ASN1_OTS)
 		return 0;
diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
index 146d86105183..ea1d860c0040 100644
--- a/net/ipv4/netfilter/nf_reject_ipv4.c
+++ b/net/ipv4/netfilter/nf_reject_ipv4.c
@@ -29,7 +29,7 @@ const struct tcphdr *nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,
 
 	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
 				 sizeof(struct tcphdr), _oth);
-	if (oth == NULL)
+	if (!oth)
 		return NULL;
 
 	/* No RST for RST. */
diff --git a/net/ipv4/netfilter/nf_socket_ipv4.c b/net/ipv4/netfilter/nf_socket_ipv4.c
index a83d558e1aae..777888e742f7 100644
--- a/net/ipv4/netfilter/nf_socket_ipv4.c
+++ b/net/ipv4/netfilter/nf_socket_ipv4.c
@@ -32,7 +32,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 
 	icmph = skb_header_pointer(skb, outside_hdrlen,
 				   sizeof(_icmph), &_icmph);
-	if (icmph == NULL)
+	if (!icmph)
 		return 1;
 
 	switch (icmph->type) {
@@ -49,7 +49,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 	inside_iph = skb_header_pointer(skb, outside_hdrlen +
 					sizeof(struct icmphdr),
 					sizeof(_inside_iph), &_inside_iph);
-	if (inside_iph == NULL)
+	if (!inside_iph)
 		return 1;
 
 	if (inside_iph->protocol != IPPROTO_TCP &&
@@ -60,7 +60,7 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
 				   sizeof(struct icmphdr) +
 				   (inside_iph->ihl << 2),
 				   sizeof(_ports), &_ports);
-	if (ports == NULL)
+	if (!ports)
 		return 1;
 
 	/* the inside IP packet is the one quoted from our side, thus
@@ -112,7 +112,7 @@ struct sock *nf_sk_lookup_slow_v4(struct net *net, const struct sk_buff *skb,
 
 		hp = skb_header_pointer(skb, ip_hdrlen(skb),
 					sizeof(_hdr), &_hdr);
-		if (hp == NULL)
+		if (!hp)
 			return NULL;
 
 		protocol = iph->protocol;
diff --git a/net/ipv4/netfilter/nf_tables_arp.c b/net/ipv4/netfilter/nf_tables_arp.c
index 805c8ddfe860..3634f0df42f7 100644
--- a/net/ipv4/netfilter/nf_tables_arp.c
+++ b/net/ipv4/netfilter/nf_tables_arp.c
@@ -41,7 +41,7 @@ static struct nft_af_info nft_af_arp __read_mostly = {
 static int nf_tables_arp_init_net(struct net *net)
 {
 	net->nft.arp = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
-	if (net->nft.arp== NULL)
+	if (!net->nft.arp)
 		return -ENOMEM;
 
 	memcpy(net->nft.arp, &nft_af_arp, sizeof(nft_af_arp));
diff --git a/net/ipv4/netfilter/nf_tables_ipv4.c b/net/ipv4/netfilter/nf_tables_ipv4.c
index 2840a29b2e04..bedbd62ab755 100644
--- a/net/ipv4/netfilter/nf_tables_ipv4.c
+++ b/net/ipv4/netfilter/nf_tables_ipv4.c
@@ -62,7 +62,7 @@ EXPORT_SYMBOL_GPL(nft_af_ipv4);
 static int nf_tables_ipv4_init_net(struct net *net)
 {
 	net->nft.ipv4 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
-	if (net->nft.ipv4 == NULL)
+	if (!net->nft.ipv4)
 		return -ENOMEM;
 
 	memcpy(net->nft.ipv4, &nft_af_ipv4, sizeof(nft_af_ipv4));
diff --git a/net/ipv4/netfilter/nft_dup_ipv4.c b/net/ipv4/netfilter/nft_dup_ipv4.c
index 0af3d8df70dd..362c4eaa8187 100644
--- a/net/ipv4/netfilter/nft_dup_ipv4.c
+++ b/net/ipv4/netfilter/nft_dup_ipv4.c
@@ -40,7 +40,7 @@ static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
 	struct nft_dup_ipv4 *priv = nft_expr_priv(expr);
 	int err;
 
-	if (tb[NFTA_DUP_SREG_ADDR] == NULL)
+	if (!tb[NFTA_DUP_SREG_ADDR])
 		return -EINVAL;
 
 	priv->sreg_addr = nft_parse_register(tb[NFTA_DUP_SREG_ADDR]);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-02  5:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01 16:13 [PATCH 0/2] Simplify NULL comparisons Arushi Singhal
2017-04-01 16:13 ` [PATCH 1/2] ipv4: netfilter: " Arushi Singhal
2017-04-01 16:13 ` [PATCH 2/2] ipv6: " Arushi Singhal
2017-04-02  5:31 [PATCH 1/2] ipv4: " Arushi Singhal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.