Skip to content

Commit 8690bfa

Browse files
author
Andy Grover
committed
RDS: cleanup: remove "== NULL"s and "!= NULL"s in ptr comparisons
Favor "if (foo)" style over "if (foo != NULL)". Signed-off-by: Andy Grover <andy.grover@oracle.com>
1 parent 2dc3935 commit 8690bfa

26 files changed

Lines changed: 90 additions & 90 deletions

‎net/rds/af_rds.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int rds_release(struct socket *sock)
6262
struct rds_sock *rs;
6363
unsigned long flags;
6464

65-
if (sk == NULL)
65+
if (!sk)
6666
goto out;
6767

6868
rs = rds_sk_to_rs(sk);

‎net/rds/bind.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int rds_add_bound(struct rds_sock *rs, __be32 addr, __be16 *port)
121121
do {
122122
if (rover == 0)
123123
rover++;
124-
if (rds_bind_tree_walk(addr, cpu_to_be16(rover), rs) == NULL) {
124+
if (!rds_bind_tree_walk(addr, cpu_to_be16(rover), rs)) {
125125
*port = cpu_to_be16(rover);
126126
ret = 0;
127127
break;
@@ -184,7 +184,7 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
184184
goto out;
185185

186186
trans = rds_trans_get_preferred(sin->sin_addr.s_addr);
187-
if (trans == NULL) {
187+
if (!trans) {
188188
ret = -EADDRNOTAVAIL;
189189
rds_remove_bound(rs);
190190
if (printk_ratelimit())

‎net/rds/cong.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static struct rds_cong_map *rds_cong_from_addr(__be32 addr)
141141
unsigned long flags;
142142

143143
map = kzalloc(sizeof(struct rds_cong_map), GFP_KERNEL);
144-
if (map == NULL)
144+
if (!map)
145145
return NULL;
146146

147147
map->m_addr = addr;
@@ -159,7 +159,7 @@ static struct rds_cong_map *rds_cong_from_addr(__be32 addr)
159159
ret = rds_cong_tree_walk(addr, map);
160160
spin_unlock_irqrestore(&rds_cong_lock, flags);
161161

162-
if (ret == NULL) {
162+
if (!ret) {
163163
ret = map;
164164
map = NULL;
165165
}
@@ -205,7 +205,7 @@ int rds_cong_get_maps(struct rds_connection *conn)
205205
conn->c_lcong = rds_cong_from_addr(conn->c_laddr);
206206
conn->c_fcong = rds_cong_from_addr(conn->c_faddr);
207207

208-
if (conn->c_lcong == NULL || conn->c_fcong == NULL)
208+
if (!(conn->c_lcong && conn->c_fcong))
209209
return -ENOMEM;
210210

211211
return 0;

‎net/rds/connection.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
148148
goto out;
149149

150150
conn = kmem_cache_zalloc(rds_conn_slab, gfp);
151-
if (conn == NULL) {
151+
if (!conn) {
152152
conn = ERR_PTR(-ENOMEM);
153153
goto out;
154154
}
@@ -502,7 +502,7 @@ int __init rds_conn_init(void)
502502
rds_conn_slab = kmem_cache_create("rds_connection",
503503
sizeof(struct rds_connection),
504504
0, 0, NULL);
505-
if (rds_conn_slab == NULL)
505+
if (!rds_conn_slab)
506506
return -ENOMEM;
507507

508508
rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);

‎net/rds/ib_cm.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
230230
* the rds_ibdev at all.
231231
*/
232232
rds_ibdev = ib_get_client_data(dev, &rds_ib_client);
233-
if (rds_ibdev == NULL) {
233+
if (!rds_ibdev) {
234234
if (printk_ratelimit())
235235
printk(KERN_NOTICE "RDS/IB: No client_data for device %s\n",
236236
dev->name);
@@ -306,7 +306,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
306306
ic->i_send_ring.w_nr *
307307
sizeof(struct rds_header),
308308
&ic->i_send_hdrs_dma, GFP_KERNEL);
309-
if (ic->i_send_hdrs == NULL) {
309+
if (!ic->i_send_hdrs) {
310310
ret = -ENOMEM;
311311
rdsdebug("ib_dma_alloc_coherent send failed\n");
312312
goto out;
@@ -316,30 +316,30 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
316316
ic->i_recv_ring.w_nr *
317317
sizeof(struct rds_header),
318318
&ic->i_recv_hdrs_dma, GFP_KERNEL);
319-
if (ic->i_recv_hdrs == NULL) {
319+
if (!ic->i_recv_hdrs) {
320320
ret = -ENOMEM;
321321
rdsdebug("ib_dma_alloc_coherent recv failed\n");
322322
goto out;
323323
}
324324

325325
ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
326326
&ic->i_ack_dma, GFP_KERNEL);
327-
if (ic->i_ack == NULL) {
327+
if (!ic->i_ack) {
328328
ret = -ENOMEM;
329329
rdsdebug("ib_dma_alloc_coherent ack failed\n");
330330
goto out;
331331
}
332332

333333
ic->i_sends = vmalloc(ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work));
334-
if (ic->i_sends == NULL) {
334+
if (!ic->i_sends) {
335335
ret = -ENOMEM;
336336
rdsdebug("send allocation failed\n");
337337
goto out;
338338
}
339339
memset(ic->i_sends, 0, ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work));
340340

341341
ic->i_recvs = vmalloc(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_recv_work));
342-
if (ic->i_recvs == NULL) {
342+
if (!ic->i_recvs) {
343343
ret = -ENOMEM;
344344
rdsdebug("recv allocation failed\n");
345345
goto out;
@@ -693,7 +693,7 @@ int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp)
693693

694694
/* XXX too lazy? */
695695
ic = kzalloc(sizeof(struct rds_ib_connection), GFP_KERNEL);
696-
if (ic == NULL)
696+
if (!ic)
697697
return -ENOMEM;
698698

699699
INIT_LIST_HEAD(&ic->ib_node);

‎net/rds/ib_recv.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void rds_ib_frag_drop_page(struct rds_page_frag *frag)
5353
static void rds_ib_frag_free(struct rds_page_frag *frag)
5454
{
5555
rdsdebug("frag %p page %p\n", frag, frag->f_page);
56-
BUG_ON(frag->f_page != NULL);
56+
BUG_ON(frag->f_page);
5757
kmem_cache_free(rds_ib_frag_slab, frag);
5858
}
5959

@@ -143,32 +143,32 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
143143
struct ib_sge *sge;
144144
int ret = -ENOMEM;
145145

146-
if (recv->r_ibinc == NULL) {
146+
if (!recv->r_ibinc) {
147147
if (!atomic_add_unless(&rds_ib_allocation, 1, rds_ib_sysctl_max_recv_allocation)) {
148148
rds_ib_stats_inc(s_ib_rx_alloc_limit);
149149
goto out;
150150
}
151151
recv->r_ibinc = kmem_cache_alloc(rds_ib_incoming_slab,
152152
kptr_gfp);
153-
if (recv->r_ibinc == NULL) {
153+
if (!recv->r_ibinc) {
154154
atomic_dec(&rds_ib_allocation);
155155
goto out;
156156
}
157157
INIT_LIST_HEAD(&recv->r_ibinc->ii_frags);
158158
rds_inc_init(&recv->r_ibinc->ii_inc, conn, conn->c_faddr);
159159
}
160160

161-
if (recv->r_frag == NULL) {
161+
if (!recv->r_frag) {
162162
recv->r_frag = kmem_cache_alloc(rds_ib_frag_slab, kptr_gfp);
163-
if (recv->r_frag == NULL)
163+
if (!recv->r_frag)
164164
goto out;
165165
INIT_LIST_HEAD(&recv->r_frag->f_item);
166166
recv->r_frag->f_page = NULL;
167167
}
168168

169-
if (ic->i_frag.f_page == NULL) {
169+
if (!ic->i_frag.f_page) {
170170
ic->i_frag.f_page = alloc_page(page_gfp);
171-
if (ic->i_frag.f_page == NULL)
171+
if (!ic->i_frag.f_page)
172172
goto out;
173173
ic->i_frag.f_offset = 0;
174174
}
@@ -757,7 +757,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
757757
* into the inc and save the inc so we can hang upcoming fragments
758758
* off its list.
759759
*/
760-
if (ibinc == NULL) {
760+
if (!ibinc) {
761761
ibinc = recv->r_ibinc;
762762
recv->r_ibinc = NULL;
763763
ic->i_ibinc = ibinc;
@@ -940,13 +940,13 @@ int __init rds_ib_recv_init(void)
940940
rds_ib_incoming_slab = kmem_cache_create("rds_ib_incoming",
941941
sizeof(struct rds_ib_incoming),
942942
0, 0, NULL);
943-
if (rds_ib_incoming_slab == NULL)
943+
if (!rds_ib_incoming_slab)
944944
goto out;
945945

946946
rds_ib_frag_slab = kmem_cache_create("rds_ib_frag",
947947
sizeof(struct rds_page_frag),
948948
0, 0, NULL);
949-
if (rds_ib_frag_slab == NULL)
949+
if (!rds_ib_frag_slab)
950950
kmem_cache_destroy(rds_ib_incoming_slab);
951951
else
952952
ret = 0;

‎net/rds/ib_send.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void rds_ib_send_unmap_rm(struct rds_ib_connection *ic,
8686
rm->m_sg, rm->m_nents,
8787
DMA_TO_DEVICE);
8888

89-
if (rm->m_rdma_op != NULL) {
89+
if (rm->m_rdma_op) {
9090
rds_ib_send_unmap_rdma(ic, rm->m_rdma_op);
9191

9292
/* If the user asked for a completion notification on this
@@ -525,7 +525,7 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,
525525
}
526526

527527
/* map the message the first time we see it */
528-
if (ic->i_rm == NULL) {
528+
if (!ic->i_rm) {
529529
/*
530530
printk(KERN_NOTICE "rds_ib_xmit prep msg dport=%u flags=0x%x len=%d\n",
531531
be16_to_cpu(rm->m_inc.i_hdr.h_dport),

‎net/rds/ib_sysctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void rds_ib_sysctl_exit(void)
135135
int __init rds_ib_sysctl_init(void)
136136
{
137137
rds_ib_sysctl_hdr = register_sysctl_paths(rds_ib_sysctl_path, rds_ib_sysctl_table);
138-
if (rds_ib_sysctl_hdr == NULL)
138+
if (!rds_ib_sysctl_hdr)
139139
return -ENOMEM;
140140
return 0;
141141
}

‎net/rds/info.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void rds_info_register_func(int optname, rds_info_func func)
7676
BUG_ON(optname < RDS_INFO_FIRST || optname > RDS_INFO_LAST);
7777

7878
spin_lock(&rds_info_lock);
79-
BUG_ON(rds_info_funcs[offset] != NULL);
79+
BUG_ON(rds_info_funcs[offset]);
8080
rds_info_funcs[offset] = func;
8181
spin_unlock(&rds_info_lock);
8282
}
@@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(rds_info_deregister_func);
102102
*/
103103
void rds_info_iter_unmap(struct rds_info_iterator *iter)
104104
{
105-
if (iter->addr != NULL) {
105+
if (iter->addr) {
106106
kunmap_atomic(iter->addr, KM_USER0);
107107
iter->addr = NULL;
108108
}
@@ -117,7 +117,7 @@ void rds_info_copy(struct rds_info_iterator *iter, void *data,
117117
unsigned long this;
118118

119119
while (bytes) {
120-
if (iter->addr == NULL)
120+
if (!iter->addr)
121121
iter->addr = kmap_atomic(*iter->pages, KM_USER0);
122122

123123
this = min(bytes, PAGE_SIZE - iter->offset);
@@ -188,7 +188,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
188188
>> PAGE_SHIFT;
189189

190190
pages = kmalloc(nr_pages * sizeof(struct page *), GFP_KERNEL);
191-
if (pages == NULL) {
191+
if (!pages) {
192192
ret = -ENOMEM;
193193
goto out;
194194
}
@@ -206,7 +206,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
206206

207207
call_func:
208208
func = rds_info_funcs[optname - RDS_INFO_FIRST];
209-
if (func == NULL) {
209+
if (!func) {
210210
ret = -ENOPROTOOPT;
211211
goto out;
212212
}
@@ -234,7 +234,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
234234
ret = -EFAULT;
235235

236236
out:
237-
for (i = 0; pages != NULL && i < nr_pages; i++)
237+
for (i = 0; pages && i < nr_pages; i++)
238238
put_page(pages[i]);
239239
kfree(pages);
240240

‎net/rds/iw_cm.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int rds_iw_setup_qp(struct rds_connection *conn)
257257
* the rds_iwdev at all.
258258
*/
259259
rds_iwdev = ib_get_client_data(dev, &rds_iw_client);
260-
if (rds_iwdev == NULL) {
260+
if (!rds_iwdev) {
261261
if (printk_ratelimit())
262262
printk(KERN_NOTICE "RDS/IW: No client_data for device %s\n",
263263
dev->name);
@@ -292,7 +292,7 @@ static int rds_iw_setup_qp(struct rds_connection *conn)
292292
ic->i_send_ring.w_nr *
293293
sizeof(struct rds_header),
294294
&ic->i_send_hdrs_dma, GFP_KERNEL);
295-
if (ic->i_send_hdrs == NULL) {
295+
if (!ic->i_send_hdrs) {
296296
ret = -ENOMEM;
297297
rdsdebug("ib_dma_alloc_coherent send failed\n");
298298
goto out;
@@ -302,30 +302,30 @@ static int rds_iw_setup_qp(struct rds_connection *conn)
302302
ic->i_recv_ring.w_nr *
303303
sizeof(struct rds_header),
304304
&ic->i_recv_hdrs_dma, GFP_KERNEL);
305-
if (ic->i_recv_hdrs == NULL) {
305+
if (!ic->i_recv_hdrs) {
306306
ret = -ENOMEM;
307307
rdsdebug("ib_dma_alloc_coherent recv failed\n");
308308
goto out;
309309
}
310310

311311
ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
312312
&ic->i_ack_dma, GFP_KERNEL);
313-
if (ic->i_ack == NULL) {
313+
if (!ic->i_ack) {
314314
ret = -ENOMEM;
315315
rdsdebug("ib_dma_alloc_coherent ack failed\n");
316316
goto out;
317317
}
318318

319319
ic->i_sends = vmalloc(ic->i_send_ring.w_nr * sizeof(struct rds_iw_send_work));
320-
if (ic->i_sends == NULL) {
320+
if (!ic->i_sends) {
321321
ret = -ENOMEM;
322322
rdsdebug("send allocation failed\n");
323323
goto out;
324324
}
325325
rds_iw_send_init_ring(ic);
326326

327327
ic->i_recvs = vmalloc(ic->i_recv_ring.w_nr * sizeof(struct rds_iw_recv_work));
328-
if (ic->i_recvs == NULL) {
328+
if (!ic->i_recvs) {
329329
ret = -ENOMEM;
330330
rdsdebug("recv allocation failed\n");
331331
goto out;
@@ -696,7 +696,7 @@ int rds_iw_conn_alloc(struct rds_connection *conn, gfp_t gfp)
696696

697697
/* XXX too lazy? */
698698
ic = kzalloc(sizeof(struct rds_iw_connection), GFP_KERNEL);
699-
if (ic == NULL)
699+
if (!ic)
700700
return -ENOMEM;
701701

702702
INIT_LIST_HEAD(&ic->iw_node);

0 commit comments

Comments
 (0)