Skip to content

Commit d37b1d9

Browse files
elfringidryomov
authored andcommitted
ceph: adjust 36 checks for NULL pointers
The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written ... Thus fix the affected source code places. Signed-off-by: Markus Elfring <[email protected]> Reviewed-by: Yan, Zheng <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent b529d1b commit d37b1d9

File tree

10 files changed

+36
-36
lines changed

10 files changed

+36
-36
lines changed

fs/ceph/addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
540540

541541
/* verify this is a writeable snap context */
542542
snapc = page_snap_context(page);
543-
if (snapc == NULL) {
543+
if (!snapc) {
544544
dout("writepage %p page %p not dirty?\n", inode, page);
545545
return 0;
546546
}

fs/ceph/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void ceph_fscache_register_inode_cookie(struct inode *inode)
240240
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
241241

242242
/* No caching for filesystem */
243-
if (fsc->fscache == NULL)
243+
if (!fsc->fscache)
244244
return;
245245

246246
/* Only cache for regular files that are read only */

fs/ceph/caps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ void ceph_add_cap(struct inode *inode,
611611
}
612612

613613
if (flags & CEPH_CAP_FLAG_AUTH) {
614-
if (ci->i_auth_cap == NULL ||
614+
if (!ci->i_auth_cap ||
615615
ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) {
616616
ci->i_auth_cap = cap;
617617
cap->mds_wanted = wanted;
@@ -728,7 +728,7 @@ static void __touch_cap(struct ceph_cap *cap)
728728
struct ceph_mds_session *s = cap->session;
729729

730730
spin_lock(&s->s_cap_lock);
731-
if (s->s_cap_iterator == NULL) {
731+
if (!s->s_cap_iterator) {
732732
dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap,
733733
s->s_mds);
734734
list_move_tail(&cap->session_caps, &s->s_caps);

fs/ceph/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int mdsmap_show(struct seq_file *s, void *p)
2424
struct ceph_fs_client *fsc = s->private;
2525
struct ceph_mdsmap *mdsmap;
2626

27-
if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL)
27+
if (!fsc->mdsc || !fsc->mdsc->mdsmap)
2828
return 0;
2929
mdsmap = fsc->mdsc->mdsmap;
3030
seq_printf(s, "epoch %d\n", mdsmap->m_epoch);

fs/ceph/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
175175
dout("init_file %p %p 0%o (regular)\n", inode, file,
176176
inode->i_mode);
177177
cf = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL);
178-
if (cf == NULL) {
178+
if (!cf) {
179179
ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
180180
return -ENOMEM;
181181
}

fs/ceph/inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino)
5252
ino_t t = ceph_vino_to_ino(vino);
5353

5454
inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino);
55-
if (inode == NULL)
55+
if (!inode)
5656
return ERR_PTR(-ENOMEM);
5757
if (inode->i_state & I_NEW) {
5858
dout("get_inode created new inode %p %llx.%llx ino %llx\n",
@@ -1173,7 +1173,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
11731173
dn = d_alloc(parent, &dname);
11741174
dout("d_alloc %p '%.*s' = %p\n", parent,
11751175
dname.len, dname.name, dn);
1176-
if (dn == NULL) {
1176+
if (!dn) {
11771177
dput(parent);
11781178
err = -ENOMEM;
11791179
goto done;
@@ -1562,7 +1562,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
15621562
dn = d_alloc(parent, &dname);
15631563
dout("d_alloc %p '%.*s' = %p\n", parent,
15641564
dname.len, dname.name, dn);
1565-
if (dn == NULL) {
1565+
if (!dn) {
15661566
dout("d_alloc badness\n");
15671567
err = -ENOMEM;
15681568
goto out;

fs/ceph/mds_client.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
408408
{
409409
struct ceph_mds_session *session;
410410

411-
if (mds >= mdsc->max_sessions || mdsc->sessions[mds] == NULL)
411+
if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
412412
return NULL;
413413
session = mdsc->sessions[mds];
414414
dout("lookup_mds_session %p %d\n", session,
@@ -483,7 +483,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
483483

484484
dout("register_session realloc to %d\n", newmax);
485485
sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
486-
if (sa == NULL)
486+
if (!sa)
487487
goto fail_realloc;
488488
if (mdsc->sessions) {
489489
memcpy(sa, mdsc->sessions,
@@ -893,7 +893,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
893893

894894
/* Calculate serialized length of metadata */
895895
metadata_bytes = 4; /* map length */
896-
for (i = 0; metadata[i][0] != NULL; ++i) {
896+
for (i = 0; metadata[i][0]; ++i) {
897897
metadata_bytes += 8 + strlen(metadata[i][0]) +
898898
strlen(metadata[i][1]);
899899
metadata_key_count++;
@@ -926,7 +926,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
926926
ceph_encode_32(&p, metadata_key_count);
927927

928928
/* Two length-prefixed strings for each entry in the map */
929-
for (i = 0; metadata[i][0] != NULL; ++i) {
929+
for (i = 0; metadata[i][0]; ++i) {
930930
size_t const key_len = strlen(metadata[i][0]);
931931
size_t const val_len = strlen(metadata[i][1]);
932932

@@ -1129,7 +1129,7 @@ static int iterate_session_caps(struct ceph_mds_session *session,
11291129

11301130
spin_lock(&session->s_cap_lock);
11311131
p = p->next;
1132-
if (cap->ci == NULL) {
1132+
if (!cap->ci) {
11331133
dout("iterate_session_caps finishing cap %p removal\n",
11341134
cap);
11351135
BUG_ON(cap->session != session);
@@ -1755,7 +1755,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
17551755
int len, pos;
17561756
unsigned seq;
17571757

1758-
if (dentry == NULL)
1758+
if (!dentry)
17591759
return ERR_PTR(-EINVAL);
17601760

17611761
retry:
@@ -1778,7 +1778,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
17781778
len--; /* no leading '/' */
17791779

17801780
path = kmalloc(len+1, GFP_NOFS);
1781-
if (path == NULL)
1781+
if (!path)
17821782
return ERR_PTR(-ENOMEM);
17831783
pos = len;
17841784
path[pos] = 0; /* trailing null */
@@ -3140,7 +3140,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
31403140
newmap->m_epoch, oldmap->m_epoch);
31413141

31423142
for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) {
3143-
if (mdsc->sessions[i] == NULL)
3143+
if (!mdsc->sessions[i])
31443144
continue;
31453145
s = mdsc->sessions[i];
31463146
oldstate = ceph_mdsmap_get_state(oldmap, i);
@@ -3287,7 +3287,7 @@ static void handle_lease(struct ceph_mds_client *mdsc,
32873287
mutex_lock(&session->s_mutex);
32883288
session->s_seq++;
32893289

3290-
if (inode == NULL) {
3290+
if (!inode) {
32913291
dout("handle_lease no inode %llx\n", vino.ino);
32923292
goto release;
32933293
}
@@ -3445,7 +3445,7 @@ static void delayed_work(struct work_struct *work)
34453445

34463446
for (i = 0; i < mdsc->max_sessions; i++) {
34473447
struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
3448-
if (s == NULL)
3448+
if (!s)
34493449
continue;
34503450
if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
34513451
dout("resending session close request for mds%d\n",
@@ -3497,7 +3497,7 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
34973497
fsc->mdsc = mdsc;
34983498
mutex_init(&mdsc->mutex);
34993499
mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
3500-
if (mdsc->mdsmap == NULL) {
3500+
if (!mdsc->mdsmap) {
35013501
kfree(mdsc);
35023502
return -ENOMEM;
35033503
}

fs/ceph/mdsmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
112112
u16 mdsmap_ev;
113113

114114
m = kzalloc(sizeof(*m), GFP_NOFS);
115-
if (m == NULL)
115+
if (!m)
116116
return ERR_PTR(-ENOMEM);
117117

118118
ceph_decode_need(p, end, 1 + 1, bad);
@@ -138,7 +138,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
138138
m->m_num_mds = m->m_max_mds;
139139

140140
m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS);
141-
if (m->m_info == NULL)
141+
if (!m->m_info)
142142
goto nomem;
143143

144144
/* pick out active nodes from mds_info (state > 0) */
@@ -232,7 +232,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
232232
if (num_export_targets) {
233233
info->export_targets = kcalloc(num_export_targets,
234234
sizeof(u32), GFP_NOFS);
235-
if (info->export_targets == NULL)
235+
if (!info->export_targets)
236236
goto nomem;
237237
for (j = 0; j < num_export_targets; j++)
238238
info->export_targets[j] =

fs/ceph/super.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
594594
}
595595
fsc->client->extra_mon_dispatch = extra_mon_dispatch;
596596

597-
if (fsopt->mds_namespace == NULL) {
597+
if (!fsopt->mds_namespace) {
598598
ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
599599
0, true);
600600
} else {
@@ -615,13 +615,13 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
615615
* to be processed in parallel, limit concurrency.
616616
*/
617617
fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
618-
if (fsc->wb_wq == NULL)
618+
if (!fsc->wb_wq)
619619
goto fail_client;
620620
fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
621-
if (fsc->pg_inv_wq == NULL)
621+
if (!fsc->pg_inv_wq)
622622
goto fail_wb_wq;
623623
fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
624-
if (fsc->trunc_wq == NULL)
624+
if (!fsc->trunc_wq)
625625
goto fail_pg_inv_wq;
626626

627627
/* set up mempools */
@@ -692,26 +692,26 @@ static int __init init_caches(void)
692692
__alignof__(struct ceph_inode_info),
693693
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
694694
SLAB_ACCOUNT, ceph_inode_init_once);
695-
if (ceph_inode_cachep == NULL)
695+
if (!ceph_inode_cachep)
696696
return -ENOMEM;
697697

698698
ceph_cap_cachep = KMEM_CACHE(ceph_cap,
699699
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
700-
if (ceph_cap_cachep == NULL)
700+
if (!ceph_cap_cachep)
701701
goto bad_cap;
702702
ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
703703
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
704-
if (ceph_cap_flush_cachep == NULL)
704+
if (!ceph_cap_flush_cachep)
705705
goto bad_cap_flush;
706706

707707
ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
708708
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
709-
if (ceph_dentry_cachep == NULL)
709+
if (!ceph_dentry_cachep)
710710
goto bad_dentry;
711711

712712
ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
713713

714-
if (ceph_file_cachep == NULL)
714+
if (!ceph_file_cachep)
715715
goto bad_file;
716716

717717
if ((error = ceph_fscache_register()))

fs/ceph/xattr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
777777
spin_unlock(&ci->i_ceph_lock);
778778

779779
/* security module gets xattr while filling trace */
780-
if (current->journal_info != NULL) {
780+
if (current->journal_info) {
781781
pr_warn_ratelimited("sync getxattr %p "
782782
"during filling trace\n", inode);
783783
return -EBUSY;
@@ -809,7 +809,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
809809

810810
memcpy(value, xattr->val, xattr->val_len);
811811

812-
if (current->journal_info != NULL &&
812+
if (current->journal_info &&
813813
!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN))
814814
ci->i_ceph_flags |= CEPH_I_SEC_INITED;
815815
out:
@@ -1058,7 +1058,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
10581058
up_read(&mdsc->snap_rwsem);
10591059

10601060
/* security module set xattr while filling trace */
1061-
if (current->journal_info != NULL) {
1061+
if (current->journal_info) {
10621062
pr_warn_ratelimited("sync setxattr %p "
10631063
"during filling trace\n", inode);
10641064
err = -EBUSY;
@@ -1108,7 +1108,7 @@ bool ceph_security_xattr_deadlock(struct inode *in)
11081108
{
11091109
struct ceph_inode_info *ci;
11101110
bool ret;
1111-
if (in->i_security == NULL)
1111+
if (!in->i_security)
11121112
return false;
11131113
ci = ceph_inode(in);
11141114
spin_lock(&ci->i_ceph_lock);

0 commit comments

Comments
 (0)