Skip to content

Commit

Permalink
ipv4: coding style: comparison for equality with NULL
Browse files Browse the repository at this point in the history
The ipv4 code uses a mixture of coding styles. In some instances check
for NULL pointer is done as x == NULL and sometimes as !x. !x is
preferred according to checkpatch and this patch makes the code
consistent by adopting the latter form.

No changes detected by objdiff.

Signed-off-by: Ian Morris <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
lz7tq4 authored and davem330 committed Apr 3, 2015
1 parent 11a9c78 commit 51456b2
Show file tree
Hide file tree
Showing 39 changed files with 210 additions and 202 deletions.
6 changes: 3 additions & 3 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int inet_listen(struct socket *sock, int backlog)
* shutdown() (rather than close()).
*/
if ((sysctl_tcp_fastopen & TFO_SERVER_ENABLE) != 0 &&
inet_csk(sk)->icsk_accept_queue.fastopenq == NULL) {
!inet_csk(sk)->icsk_accept_queue.fastopenq) {
if ((sysctl_tcp_fastopen & TFO_SERVER_WO_SOCKOPT1) != 0)
err = fastopen_init_queue(sk, backlog);
else if ((sysctl_tcp_fastopen &
Expand Down Expand Up @@ -314,11 +314,11 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
answer_flags = answer->flags;
rcu_read_unlock();

WARN_ON(answer_prot->slab == NULL);
WARN_ON(!answer_prot->slab);

err = -ENOBUFS;
sk = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot);
if (sk == NULL)
if (!sk)
goto out;

err = 0;
Expand Down
26 changes: 13 additions & 13 deletions net/ipv4/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static int arp_constructor(struct neighbour *neigh)

rcu_read_lock();
in_dev = __in_dev_get_rcu(dev);
if (in_dev == NULL) {
if (!in_dev) {
rcu_read_unlock();
return -EINVAL;
}
Expand Down Expand Up @@ -475,7 +475,7 @@ static inline int arp_fwd_pvlan(struct in_device *in_dev,
*/

/*
* Create an arp packet. If (dest_hw == NULL), we create a broadcast
* Create an arp packet. If dest_hw is not set, we create a broadcast
* message.
*/
struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
Expand All @@ -495,17 +495,17 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
*/

skb = alloc_skb(arp_hdr_len(dev) + hlen + tlen, GFP_ATOMIC);
if (skb == NULL)
if (!skb)
return NULL;

skb_reserve(skb, hlen);
skb_reset_network_header(skb);
arp = (struct arphdr *) skb_put(skb, arp_hdr_len(dev));
skb->dev = dev;
skb->protocol = htons(ETH_P_ARP);
if (src_hw == NULL)
if (!src_hw)
src_hw = dev->dev_addr;
if (dest_hw == NULL)
if (!dest_hw)
dest_hw = dev->broadcast;

/*
Expand Down Expand Up @@ -614,7 +614,7 @@ void arp_send(int type, int ptype, __be32 dest_ip,

skb = arp_create(type, ptype, dest_ip, dev, src_ip,
dest_hw, src_hw, target_hw);
if (skb == NULL)
if (!skb)
return;

arp_xmit(skb);
Expand Down Expand Up @@ -644,7 +644,7 @@ static int arp_process(struct sk_buff *skb)
* is ARP'able.
*/

if (in_dev == NULL)
if (!in_dev)
goto out;

arp = arp_hdr(skb);
Expand Down Expand Up @@ -808,7 +808,7 @@ static int arp_process(struct sk_buff *skb)
is_garp = arp->ar_op == htons(ARPOP_REQUEST) && tip == sip &&
inet_addr_type(net, sip) == RTN_UNICAST;

if (n == NULL &&
if (!n &&
((arp->ar_op == htons(ARPOP_REPLY) &&
inet_addr_type(net, sip) == RTN_UNICAST) || is_garp))
n = __neigh_lookup(&arp_tbl, &sip, dev, 1);
Expand Down Expand Up @@ -900,7 +900,7 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,

static int arp_req_set_proxy(struct net *net, struct net_device *dev, int on)
{
if (dev == NULL) {
if (!dev) {
IPV4_DEVCONF_ALL(net, PROXY_ARP) = on;
return 0;
}
Expand All @@ -926,7 +926,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r,
return -ENODEV;
}
if (mask) {
if (pneigh_lookup(&arp_tbl, net, &ip, dev, 1) == NULL)
if (!pneigh_lookup(&arp_tbl, net, &ip, dev, 1))
return -ENOBUFS;
return 0;
}
Expand All @@ -947,7 +947,7 @@ static int arp_req_set(struct net *net, struct arpreq *r,
ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr;
if (r->arp_flags & ATF_PERM)
r->arp_flags |= ATF_COM;
if (dev == NULL) {
if (!dev) {
struct rtable *rt = ip_route_output(net, ip, 0, RTO_ONLINK, 0);

if (IS_ERR(rt))
Expand Down Expand Up @@ -1067,7 +1067,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
return arp_req_delete_public(net, r, dev);

ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr;
if (dev == NULL) {
if (!dev) {
struct rtable *rt = ip_route_output(net, ip, 0, RTO_ONLINK, 0);
if (IS_ERR(rt))
return PTR_ERR(rt);
Expand Down Expand Up @@ -1116,7 +1116,7 @@ int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg)
if (r.arp_dev[0]) {
err = -ENODEV;
dev = __dev_get_by_name(net, r.arp_dev);
if (dev == NULL)
if (!dev)
goto out;

/* Mmmm... It is wrong... ARPHRD_NETROM==0 */
Expand Down
36 changes: 18 additions & 18 deletions net/ipv4/cipso_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int __init cipso_v4_cache_init(void)
cipso_v4_cache = kcalloc(CIPSO_V4_CACHE_BUCKETS,
sizeof(struct cipso_v4_map_cache_bkt),
GFP_KERNEL);
if (cipso_v4_cache == NULL)
if (!cipso_v4_cache)
return -ENOMEM;

for (iter = 0; iter < CIPSO_V4_CACHE_BUCKETS; iter++) {
Expand Down Expand Up @@ -339,7 +339,7 @@ static int cipso_v4_cache_check(const unsigned char *key,
secattr->cache = entry->lsm_data;
secattr->flags |= NETLBL_SECATTR_CACHE;
secattr->type = NETLBL_NLTYPE_CIPSOV4;
if (prev_entry == NULL) {
if (!prev_entry) {
spin_unlock_bh(&cipso_v4_cache[bkt].lock);
return 0;
}
Expand Down Expand Up @@ -393,10 +393,10 @@ int cipso_v4_cache_add(const unsigned char *cipso_ptr,
cipso_ptr_len = cipso_ptr[1];

entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
if (entry == NULL)
if (!entry)
return -ENOMEM;
entry->key = kmemdup(cipso_ptr, cipso_ptr_len, GFP_ATOMIC);
if (entry->key == NULL) {
if (!entry->key) {
ret_val = -ENOMEM;
goto cache_add_failure;
}
Expand Down Expand Up @@ -547,7 +547,7 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def,
*/
void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
{
if (doi_def == NULL)
if (!doi_def)
return;

switch (doi_def->type) {
Expand Down Expand Up @@ -598,7 +598,7 @@ int cipso_v4_doi_remove(u32 doi, struct netlbl_audit *audit_info)

spin_lock(&cipso_v4_doi_list_lock);
doi_def = cipso_v4_doi_search(doi);
if (doi_def == NULL) {
if (!doi_def) {
spin_unlock(&cipso_v4_doi_list_lock);
ret_val = -ENOENT;
goto doi_remove_return;
Expand Down Expand Up @@ -644,7 +644,7 @@ struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)

rcu_read_lock();
doi_def = cipso_v4_doi_search(doi);
if (doi_def == NULL)
if (!doi_def)
goto doi_getdef_return;
if (!atomic_inc_not_zero(&doi_def->refcount))
doi_def = NULL;
Expand All @@ -664,7 +664,7 @@ struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
*/
void cipso_v4_doi_putdef(struct cipso_v4_doi *doi_def)
{
if (doi_def == NULL)
if (!doi_def)
return;

if (!atomic_dec_and_test(&doi_def->refcount))
Expand Down Expand Up @@ -1642,7 +1642,7 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)

rcu_read_lock();
doi_def = cipso_v4_doi_search(get_unaligned_be32(&opt[2]));
if (doi_def == NULL) {
if (!doi_def) {
err_offset = 2;
goto validate_return_locked;
}
Expand Down Expand Up @@ -1736,7 +1736,7 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)
* not the loopback device drop the packet. Further,
* there is no legitimate reason for setting this from
* userspace so reject it if skb is NULL. */
if (skb == NULL || !(skb->dev->flags & IFF_LOOPBACK)) {
if (!skb || !(skb->dev->flags & IFF_LOOPBACK)) {
err_offset = opt_iter;
goto validate_return_locked;
}
Expand Down Expand Up @@ -1897,15 +1897,15 @@ int cipso_v4_sock_setattr(struct sock *sk,
* defined yet but it is not a problem as the only users of these
* "lite" PF_INET sockets are functions which do an accept() call
* afterwards so we will label the socket as part of the accept(). */
if (sk == NULL)
if (!sk)
return 0;

/* We allocate the maximum CIPSO option size here so we are probably
* being a little wasteful, but it makes our life _much_ easier later
* on and after all we are only talking about 40 bytes. */
buf_len = CIPSO_V4_OPT_LEN_MAX;
buf = kmalloc(buf_len, GFP_ATOMIC);
if (buf == NULL) {
if (!buf) {
ret_val = -ENOMEM;
goto socket_setattr_failure;
}
Expand All @@ -1921,7 +1921,7 @@ int cipso_v4_sock_setattr(struct sock *sk,
* set the IPOPT_CIPSO option. */
opt_len = (buf_len + 3) & ~3;
opt = kzalloc(sizeof(*opt) + opt_len, GFP_ATOMIC);
if (opt == NULL) {
if (!opt) {
ret_val = -ENOMEM;
goto socket_setattr_failure;
}
Expand Down Expand Up @@ -1981,7 +1981,7 @@ int cipso_v4_req_setattr(struct request_sock *req,
* on and after all we are only talking about 40 bytes. */
buf_len = CIPSO_V4_OPT_LEN_MAX;
buf = kmalloc(buf_len, GFP_ATOMIC);
if (buf == NULL) {
if (!buf) {
ret_val = -ENOMEM;
goto req_setattr_failure;
}
Expand All @@ -1997,7 +1997,7 @@ int cipso_v4_req_setattr(struct request_sock *req,
* set the IPOPT_CIPSO option. */
opt_len = (buf_len + 3) & ~3;
opt = kzalloc(sizeof(*opt) + opt_len, GFP_ATOMIC);
if (opt == NULL) {
if (!opt) {
ret_val = -ENOMEM;
goto req_setattr_failure;
}
Expand Down Expand Up @@ -2102,7 +2102,7 @@ void cipso_v4_sock_delattr(struct sock *sk)

sk_inet = inet_sk(sk);
opt = rcu_dereference_protected(sk_inet->inet_opt, 1);
if (opt == NULL || opt->opt.cipso == 0)
if (!opt || opt->opt.cipso == 0)
return;

hdr_delta = cipso_v4_delopt(&sk_inet->inet_opt);
Expand All @@ -2128,7 +2128,7 @@ void cipso_v4_req_delattr(struct request_sock *req)

req_inet = inet_rsk(req);
opt = req_inet->opt;
if (opt == NULL || opt->opt.cipso == 0)
if (!opt || opt->opt.cipso == 0)
return;

cipso_v4_delopt(&req_inet->opt);
Expand Down Expand Up @@ -2157,7 +2157,7 @@ int cipso_v4_getattr(const unsigned char *cipso,
doi = get_unaligned_be32(&cipso[2]);
rcu_read_lock();
doi_def = cipso_v4_doi_search(doi);
if (doi_def == NULL)
if (!doi_def)
goto getattr_return;
/* XXX - This code assumes only one tag per CIPSO option which isn't
* really a good assumption to make but since we only support the MAC
Expand Down
Loading

0 comments on commit 51456b2

Please sign in to comment.