Commit d37b1d99 authored by Markus Elfring's avatar Markus Elfring Committed by Ilya Dryomov

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: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Reviewed-by: default avatarYan, Zheng <zyan@redhat.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent b529d1b3
...@@ -540,7 +540,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) ...@@ -540,7 +540,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
/* verify this is a writeable snap context */ /* verify this is a writeable snap context */
snapc = page_snap_context(page); snapc = page_snap_context(page);
if (snapc == NULL) { if (!snapc) {
dout("writepage %p page %p not dirty?\n", inode, page); dout("writepage %p page %p not dirty?\n", inode, page);
return 0; return 0;
} }
......
...@@ -240,7 +240,7 @@ void ceph_fscache_register_inode_cookie(struct inode *inode) ...@@ -240,7 +240,7 @@ void ceph_fscache_register_inode_cookie(struct inode *inode)
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
/* No caching for filesystem */ /* No caching for filesystem */
if (fsc->fscache == NULL) if (!fsc->fscache)
return; return;
/* Only cache for regular files that are read only */ /* Only cache for regular files that are read only */
......
...@@ -611,7 +611,7 @@ void ceph_add_cap(struct inode *inode, ...@@ -611,7 +611,7 @@ void ceph_add_cap(struct inode *inode,
} }
if (flags & CEPH_CAP_FLAG_AUTH) { if (flags & CEPH_CAP_FLAG_AUTH) {
if (ci->i_auth_cap == NULL || if (!ci->i_auth_cap ||
ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) { ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) {
ci->i_auth_cap = cap; ci->i_auth_cap = cap;
cap->mds_wanted = wanted; cap->mds_wanted = wanted;
...@@ -728,7 +728,7 @@ static void __touch_cap(struct ceph_cap *cap) ...@@ -728,7 +728,7 @@ static void __touch_cap(struct ceph_cap *cap)
struct ceph_mds_session *s = cap->session; struct ceph_mds_session *s = cap->session;
spin_lock(&s->s_cap_lock); spin_lock(&s->s_cap_lock);
if (s->s_cap_iterator == NULL) { if (!s->s_cap_iterator) {
dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap, dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap,
s->s_mds); s->s_mds);
list_move_tail(&cap->session_caps, &s->s_caps); list_move_tail(&cap->session_caps, &s->s_caps);
......
...@@ -24,7 +24,7 @@ static int mdsmap_show(struct seq_file *s, void *p) ...@@ -24,7 +24,7 @@ static int mdsmap_show(struct seq_file *s, void *p)
struct ceph_fs_client *fsc = s->private; struct ceph_fs_client *fsc = s->private;
struct ceph_mdsmap *mdsmap; struct ceph_mdsmap *mdsmap;
if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL) if (!fsc->mdsc || !fsc->mdsc->mdsmap)
return 0; return 0;
mdsmap = fsc->mdsc->mdsmap; mdsmap = fsc->mdsc->mdsmap;
seq_printf(s, "epoch %d\n", mdsmap->m_epoch); seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
......
...@@ -175,7 +175,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode) ...@@ -175,7 +175,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
dout("init_file %p %p 0%o (regular)\n", inode, file, dout("init_file %p %p 0%o (regular)\n", inode, file,
inode->i_mode); inode->i_mode);
cf = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL); cf = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL);
if (cf == NULL) { if (!cf) {
ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */ ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -52,7 +52,7 @@ struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino) ...@@ -52,7 +52,7 @@ struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino)
ino_t t = ceph_vino_to_ino(vino); ino_t t = ceph_vino_to_ino(vino);
inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino); inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino);
if (inode == NULL) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (inode->i_state & I_NEW) { if (inode->i_state & I_NEW) {
dout("get_inode created new inode %p %llx.%llx ino %llx\n", 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) ...@@ -1173,7 +1173,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
dn = d_alloc(parent, &dname); dn = d_alloc(parent, &dname);
dout("d_alloc %p '%.*s' = %p\n", parent, dout("d_alloc %p '%.*s' = %p\n", parent,
dname.len, dname.name, dn); dname.len, dname.name, dn);
if (dn == NULL) { if (!dn) {
dput(parent); dput(parent);
err = -ENOMEM; err = -ENOMEM;
goto done; goto done;
...@@ -1562,7 +1562,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req, ...@@ -1562,7 +1562,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
dn = d_alloc(parent, &dname); dn = d_alloc(parent, &dname);
dout("d_alloc %p '%.*s' = %p\n", parent, dout("d_alloc %p '%.*s' = %p\n", parent,
dname.len, dname.name, dn); dname.len, dname.name, dn);
if (dn == NULL) { if (!dn) {
dout("d_alloc badness\n"); dout("d_alloc badness\n");
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
......
...@@ -408,7 +408,7 @@ struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, ...@@ -408,7 +408,7 @@ struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
{ {
struct ceph_mds_session *session; struct ceph_mds_session *session;
if (mds >= mdsc->max_sessions || mdsc->sessions[mds] == NULL) if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
return NULL; return NULL;
session = mdsc->sessions[mds]; session = mdsc->sessions[mds];
dout("lookup_mds_session %p %d\n", session, dout("lookup_mds_session %p %d\n", session,
...@@ -483,7 +483,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, ...@@ -483,7 +483,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
dout("register_session realloc to %d\n", newmax); dout("register_session realloc to %d\n", newmax);
sa = kcalloc(newmax, sizeof(void *), GFP_NOFS); sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
if (sa == NULL) if (!sa)
goto fail_realloc; goto fail_realloc;
if (mdsc->sessions) { if (mdsc->sessions) {
memcpy(sa, mdsc->sessions, memcpy(sa, mdsc->sessions,
...@@ -893,7 +893,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6 ...@@ -893,7 +893,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
/* Calculate serialized length of metadata */ /* Calculate serialized length of metadata */
metadata_bytes = 4; /* map length */ metadata_bytes = 4; /* map length */
for (i = 0; metadata[i][0] != NULL; ++i) { for (i = 0; metadata[i][0]; ++i) {
metadata_bytes += 8 + strlen(metadata[i][0]) + metadata_bytes += 8 + strlen(metadata[i][0]) +
strlen(metadata[i][1]); strlen(metadata[i][1]);
metadata_key_count++; metadata_key_count++;
...@@ -926,7 +926,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6 ...@@ -926,7 +926,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
ceph_encode_32(&p, metadata_key_count); ceph_encode_32(&p, metadata_key_count);
/* Two length-prefixed strings for each entry in the map */ /* Two length-prefixed strings for each entry in the map */
for (i = 0; metadata[i][0] != NULL; ++i) { for (i = 0; metadata[i][0]; ++i) {
size_t const key_len = strlen(metadata[i][0]); size_t const key_len = strlen(metadata[i][0]);
size_t const val_len = strlen(metadata[i][1]); size_t const val_len = strlen(metadata[i][1]);
...@@ -1129,7 +1129,7 @@ static int iterate_session_caps(struct ceph_mds_session *session, ...@@ -1129,7 +1129,7 @@ static int iterate_session_caps(struct ceph_mds_session *session,
spin_lock(&session->s_cap_lock); spin_lock(&session->s_cap_lock);
p = p->next; p = p->next;
if (cap->ci == NULL) { if (!cap->ci) {
dout("iterate_session_caps finishing cap %p removal\n", dout("iterate_session_caps finishing cap %p removal\n",
cap); cap);
BUG_ON(cap->session != session); BUG_ON(cap->session != session);
...@@ -1755,7 +1755,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base, ...@@ -1755,7 +1755,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
int len, pos; int len, pos;
unsigned seq; unsigned seq;
if (dentry == NULL) if (!dentry)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
retry: retry:
...@@ -1778,7 +1778,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base, ...@@ -1778,7 +1778,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
len--; /* no leading '/' */ len--; /* no leading '/' */
path = kmalloc(len+1, GFP_NOFS); path = kmalloc(len+1, GFP_NOFS);
if (path == NULL) if (!path)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
pos = len; pos = len;
path[pos] = 0; /* trailing null */ path[pos] = 0; /* trailing null */
...@@ -3140,7 +3140,7 @@ static void check_new_map(struct ceph_mds_client *mdsc, ...@@ -3140,7 +3140,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
newmap->m_epoch, oldmap->m_epoch); newmap->m_epoch, oldmap->m_epoch);
for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) { for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) {
if (mdsc->sessions[i] == NULL) if (!mdsc->sessions[i])
continue; continue;
s = mdsc->sessions[i]; s = mdsc->sessions[i];
oldstate = ceph_mdsmap_get_state(oldmap, i); oldstate = ceph_mdsmap_get_state(oldmap, i);
...@@ -3287,7 +3287,7 @@ static void handle_lease(struct ceph_mds_client *mdsc, ...@@ -3287,7 +3287,7 @@ static void handle_lease(struct ceph_mds_client *mdsc,
mutex_lock(&session->s_mutex); mutex_lock(&session->s_mutex);
session->s_seq++; session->s_seq++;
if (inode == NULL) { if (!inode) {
dout("handle_lease no inode %llx\n", vino.ino); dout("handle_lease no inode %llx\n", vino.ino);
goto release; goto release;
} }
...@@ -3445,7 +3445,7 @@ static void delayed_work(struct work_struct *work) ...@@ -3445,7 +3445,7 @@ static void delayed_work(struct work_struct *work)
for (i = 0; i < mdsc->max_sessions; i++) { for (i = 0; i < mdsc->max_sessions; i++) {
struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
if (s == NULL) if (!s)
continue; continue;
if (s->s_state == CEPH_MDS_SESSION_CLOSING) { if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
dout("resending session close request for mds%d\n", dout("resending session close request for mds%d\n",
...@@ -3497,7 +3497,7 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc) ...@@ -3497,7 +3497,7 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
fsc->mdsc = mdsc; fsc->mdsc = mdsc;
mutex_init(&mdsc->mutex); mutex_init(&mdsc->mutex);
mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
if (mdsc->mdsmap == NULL) { if (!mdsc->mdsmap) {
kfree(mdsc); kfree(mdsc);
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -112,7 +112,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) ...@@ -112,7 +112,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
u16 mdsmap_ev; u16 mdsmap_ev;
m = kzalloc(sizeof(*m), GFP_NOFS); m = kzalloc(sizeof(*m), GFP_NOFS);
if (m == NULL) if (!m)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ceph_decode_need(p, end, 1 + 1, bad); ceph_decode_need(p, end, 1 + 1, bad);
...@@ -138,7 +138,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) ...@@ -138,7 +138,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
m->m_num_mds = m->m_max_mds; m->m_num_mds = m->m_max_mds;
m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS); m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS);
if (m->m_info == NULL) if (!m->m_info)
goto nomem; goto nomem;
/* pick out active nodes from mds_info (state > 0) */ /* pick out active nodes from mds_info (state > 0) */
...@@ -232,7 +232,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) ...@@ -232,7 +232,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
if (num_export_targets) { if (num_export_targets) {
info->export_targets = kcalloc(num_export_targets, info->export_targets = kcalloc(num_export_targets,
sizeof(u32), GFP_NOFS); sizeof(u32), GFP_NOFS);
if (info->export_targets == NULL) if (!info->export_targets)
goto nomem; goto nomem;
for (j = 0; j < num_export_targets; j++) for (j = 0; j < num_export_targets; j++)
info->export_targets[j] = info->export_targets[j] =
......
...@@ -594,7 +594,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, ...@@ -594,7 +594,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
} }
fsc->client->extra_mon_dispatch = extra_mon_dispatch; fsc->client->extra_mon_dispatch = extra_mon_dispatch;
if (fsopt->mds_namespace == NULL) { if (!fsopt->mds_namespace) {
ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP, ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
0, true); 0, true);
} else { } else {
...@@ -615,13 +615,13 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, ...@@ -615,13 +615,13 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
* to be processed in parallel, limit concurrency. * to be processed in parallel, limit concurrency.
*/ */
fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1); fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
if (fsc->wb_wq == NULL) if (!fsc->wb_wq)
goto fail_client; goto fail_client;
fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1); fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
if (fsc->pg_inv_wq == NULL) if (!fsc->pg_inv_wq)
goto fail_wb_wq; goto fail_wb_wq;
fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1); fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
if (fsc->trunc_wq == NULL) if (!fsc->trunc_wq)
goto fail_pg_inv_wq; goto fail_pg_inv_wq;
/* set up mempools */ /* set up mempools */
...@@ -692,26 +692,26 @@ static int __init init_caches(void) ...@@ -692,26 +692,26 @@ static int __init init_caches(void)
__alignof__(struct ceph_inode_info), __alignof__(struct ceph_inode_info),
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD| SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
SLAB_ACCOUNT, ceph_inode_init_once); SLAB_ACCOUNT, ceph_inode_init_once);
if (ceph_inode_cachep == NULL) if (!ceph_inode_cachep)
return -ENOMEM; return -ENOMEM;
ceph_cap_cachep = KMEM_CACHE(ceph_cap, ceph_cap_cachep = KMEM_CACHE(ceph_cap,
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
if (ceph_cap_cachep == NULL) if (!ceph_cap_cachep)
goto bad_cap; goto bad_cap;
ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush, ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
if (ceph_cap_flush_cachep == NULL) if (!ceph_cap_flush_cachep)
goto bad_cap_flush; goto bad_cap_flush;
ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info, ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
if (ceph_dentry_cachep == NULL) if (!ceph_dentry_cachep)
goto bad_dentry; goto bad_dentry;
ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
if (ceph_file_cachep == NULL) if (!ceph_file_cachep)
goto bad_file; goto bad_file;
if ((error = ceph_fscache_register())) if ((error = ceph_fscache_register()))
......
...@@ -777,7 +777,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value, ...@@ -777,7 +777,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
/* security module gets xattr while filling trace */ /* security module gets xattr while filling trace */
if (current->journal_info != NULL) { if (current->journal_info) {
pr_warn_ratelimited("sync getxattr %p " pr_warn_ratelimited("sync getxattr %p "
"during filling trace\n", inode); "during filling trace\n", inode);
return -EBUSY; return -EBUSY;
...@@ -809,7 +809,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value, ...@@ -809,7 +809,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
memcpy(value, xattr->val, xattr->val_len); memcpy(value, xattr->val, xattr->val_len);
if (current->journal_info != NULL && if (current->journal_info &&
!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)) !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN))
ci->i_ceph_flags |= CEPH_I_SEC_INITED; ci->i_ceph_flags |= CEPH_I_SEC_INITED;
out: out:
...@@ -1058,7 +1058,7 @@ int __ceph_setxattr(struct inode *inode, const char *name, ...@@ -1058,7 +1058,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
up_read(&mdsc->snap_rwsem); up_read(&mdsc->snap_rwsem);
/* security module set xattr while filling trace */ /* security module set xattr while filling trace */
if (current->journal_info != NULL) { if (current->journal_info) {
pr_warn_ratelimited("sync setxattr %p " pr_warn_ratelimited("sync setxattr %p "
"during filling trace\n", inode); "during filling trace\n", inode);
err = -EBUSY; err = -EBUSY;
...@@ -1108,7 +1108,7 @@ bool ceph_security_xattr_deadlock(struct inode *in) ...@@ -1108,7 +1108,7 @@ bool ceph_security_xattr_deadlock(struct inode *in)
{ {
struct ceph_inode_info *ci; struct ceph_inode_info *ci;
bool ret; bool ret;
if (in->i_security == NULL) if (!in->i_security)
return false; return false;
ci = ceph_inode(in); ci = ceph_inode(in);
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment