提交 561fb35a 编写于 作者: B Bhanusree Pola 提交者: Greg Kroah-Hartman

staging: erofs: Use !x or x in place of NULL comparision

Test for NULL as !x instead of NULL comparisions.
Issue found using coccinelle
Semantic patch used to solve the problem is as follows

// <smpl>
@@
expression x;
statement S;
@@

x = (\(kmalloc\|devm_kzalloc\|kmalloc_array\|devm_ioremap\|
usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\)(...));

-if(x==NULL)
+if(!x)
S

@@
expression e;
@@

-e == NULL
+!e
// </smpl>
Signed-off-by: NBhanusree Pola <bhanusreemahesh@gmail.com>
[ Gao Xiang: fix x != NULL comparision to x as well. ]
Signed-off-by: NGao Xiang <gaoxiang25@huawei.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 51385436
...@@ -129,7 +129,7 @@ static int fill_inline_data(struct inode *inode, void *data, ...@@ -129,7 +129,7 @@ static int fill_inline_data(struct inode *inode, void *data,
if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) { if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) {
char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL); char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL);
if (unlikely(lnk == NULL)) if (unlikely(!lnk))
return -ENOMEM; return -ENOMEM;
m_pofs += vi->inode_isize + vi->xattr_isize; m_pofs += vi->inode_isize + vi->xattr_isize;
...@@ -265,7 +265,7 @@ struct inode *erofs_iget(struct super_block *sb, ...@@ -265,7 +265,7 @@ struct inode *erofs_iget(struct super_block *sb,
{ {
struct inode *inode = erofs_iget_locked(sb, nid); struct inode *inode = erofs_iget_locked(sb, nid);
if (unlikely(inode == NULL)) if (unlikely(!inode))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (inode->i_state & I_NEW) { if (inode->i_state & I_NEW) {
......
...@@ -469,7 +469,7 @@ erofs_grab_bio(struct super_block *sb, ...@@ -469,7 +469,7 @@ erofs_grab_bio(struct super_block *sb,
do { do {
if (nr_pages == 1) { if (nr_pages == 1) {
bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1); bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1);
if (unlikely(bio == NULL)) { if (unlikely(!bio)) {
DBG_BUGON(nofail); DBG_BUGON(nofail);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -477,7 +477,7 @@ erofs_grab_bio(struct super_block *sb, ...@@ -477,7 +477,7 @@ erofs_grab_bio(struct super_block *sb,
} }
bio = bio_alloc(gfp, nr_pages); bio = bio_alloc(gfp, nr_pages);
nr_pages /= 2; nr_pages /= 2;
} while (unlikely(bio == NULL)); } while (unlikely(!bio));
bio->bi_end_io = endio; bio->bi_end_io = endio;
bio_set_dev(bio, sb->s_bdev); bio_set_dev(bio, sb->s_bdev);
...@@ -565,7 +565,7 @@ static inline void *erofs_vmap(struct page **pages, unsigned int count) ...@@ -565,7 +565,7 @@ static inline void *erofs_vmap(struct page **pages, unsigned int count)
while (1) { while (1) {
void *addr = vm_map_ram(pages, count, -1, PAGE_KERNEL); void *addr = vm_map_ram(pages, count, -1, PAGE_KERNEL);
/* retry two more times (totally 3 times) */ /* retry two more times (totally 3 times) */
if (addr != NULL || ++i >= 3) if (addr || ++i >= 3)
return addr; return addr;
vm_unmap_aliases(); vm_unmap_aliases();
} }
......
...@@ -240,7 +240,7 @@ static int parse_options(struct super_block *sb, char *options) ...@@ -240,7 +240,7 @@ static int parse_options(struct super_block *sb, char *options)
if (!options) if (!options)
return 0; return 0;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ","))) {
int token; int token;
if (!*p) if (!*p)
......
...@@ -43,7 +43,7 @@ struct z_erofs_pagevec_ctor { ...@@ -43,7 +43,7 @@ struct z_erofs_pagevec_ctor {
static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor, static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor,
bool atomic) bool atomic)
{ {
if (ctor->curr == NULL) if (!ctor->curr)
return; return;
if (atomic) if (atomic)
...@@ -59,7 +59,7 @@ z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor, ...@@ -59,7 +59,7 @@ z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
unsigned index; unsigned index;
/* keep away from occupied pages */ /* keep away from occupied pages */
if (ctor->next != NULL) if (ctor->next)
return ctor->next; return ctor->next;
for (index = 0; index < nr; ++index) { for (index = 0; index < nr; ++index) {
...@@ -121,7 +121,7 @@ z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor, ...@@ -121,7 +121,7 @@ z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor,
bool *occupied) bool *occupied)
{ {
*occupied = false; *occupied = false;
if (unlikely(ctor->next == NULL && type)) if (unlikely(!ctor->next && type))
if (ctor->index + 1 == ctor->nr) if (ctor->index + 1 == ctor->nr)
return false; return false;
......
...@@ -61,7 +61,7 @@ struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb, ...@@ -61,7 +61,7 @@ struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
repeat: repeat:
rcu_read_lock(); rcu_read_lock();
grp = radix_tree_lookup(&sbi->workstn_tree, index); grp = radix_tree_lookup(&sbi->workstn_tree, index);
if (grp != NULL) { if (grp) {
*tag = xa_pointer_tag(grp); *tag = xa_pointer_tag(grp);
grp = xa_untag_pointer(grp); grp = xa_untag_pointer(grp);
......
...@@ -36,7 +36,7 @@ static inline void xattr_iter_end(struct xattr_iter *it, bool atomic) ...@@ -36,7 +36,7 @@ static inline void xattr_iter_end(struct xattr_iter *it, bool atomic)
static inline void xattr_iter_end_final(struct xattr_iter *it) static inline void xattr_iter_end_final(struct xattr_iter *it)
{ {
if (it->page == NULL) if (!it->page)
return; return;
xattr_iter_end(it, true); xattr_iter_end(it, true);
...@@ -107,7 +107,7 @@ static int init_inode_xattrs(struct inode *inode) ...@@ -107,7 +107,7 @@ static int init_inode_xattrs(struct inode *inode)
vi->xattr_shared_count = ih->h_shared_count; vi->xattr_shared_count = ih->h_shared_count;
vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count, vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,
sizeof(uint), GFP_KERNEL); sizeof(uint), GFP_KERNEL);
if (vi->xattr_shared_xattrs == NULL) { if (!vi->xattr_shared_xattrs) {
xattr_iter_end(&it, atomic_map); xattr_iter_end(&it, atomic_map);
ret = -ENOMEM; ret = -ENOMEM;
goto out_unlock; goto out_unlock;
...@@ -235,7 +235,7 @@ static int xattr_foreach(struct xattr_iter *it, ...@@ -235,7 +235,7 @@ static int xattr_foreach(struct xattr_iter *it,
* therefore entry should be in the page * therefore entry should be in the page
*/ */
entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
if (tlimit != NULL) { if (tlimit) {
unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry); unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry);
BUG_ON(*tlimit < entry_sz); BUG_ON(*tlimit < entry_sz);
...@@ -282,7 +282,7 @@ static int xattr_foreach(struct xattr_iter *it, ...@@ -282,7 +282,7 @@ static int xattr_foreach(struct xattr_iter *it,
/* 3. handle xattr value */ /* 3. handle xattr value */
processed = 0; processed = 0;
if (op->alloc_buffer != NULL) { if (op->alloc_buffer) {
err = op->alloc_buffer(it, value_sz); err = op->alloc_buffer(it, value_sz);
if (err) { if (err) {
it->ofs += value_sz; it->ofs += value_sz;
...@@ -345,7 +345,7 @@ static int xattr_checkbuffer(struct xattr_iter *_it, ...@@ -345,7 +345,7 @@ static int xattr_checkbuffer(struct xattr_iter *_it,
int err = it->buffer_size < value_sz ? -ERANGE : 0; int err = it->buffer_size < value_sz ? -ERANGE : 0;
it->buffer_size = value_sz; it->buffer_size = value_sz;
return it->buffer == NULL ? 1 : err; return !it->buffer ? 1 : err;
} }
static void xattr_copyvalue(struct xattr_iter *_it, static void xattr_copyvalue(struct xattr_iter *_it,
...@@ -437,7 +437,7 @@ int erofs_getxattr(struct inode *inode, int index, ...@@ -437,7 +437,7 @@ int erofs_getxattr(struct inode *inode, int index,
int ret; int ret;
struct getxattr_iter it; struct getxattr_iter it;
if (unlikely(name == NULL)) if (unlikely(!name))
return -EINVAL; return -EINVAL;
ret = init_inode_xattrs(inode); ret = init_inode_xattrs(inode);
...@@ -539,13 +539,13 @@ static int xattr_entrylist(struct xattr_iter *_it, ...@@ -539,13 +539,13 @@ static int xattr_entrylist(struct xattr_iter *_it,
const struct xattr_handler *h = const struct xattr_handler *h =
erofs_xattr_handler(entry->e_name_index); erofs_xattr_handler(entry->e_name_index);
if (h == NULL || (h->list != NULL && !h->list(it->dentry))) if (!h || (h->list && !h->list(it->dentry)))
return 1; return 1;
prefix = xattr_prefix(h); prefix = xattr_prefix(h);
prefix_len = strlen(prefix); prefix_len = strlen(prefix);
if (it->buffer == NULL) { if (!it->buffer) {
it->buffer_ofs += prefix_len + entry->e_name_len + 1; it->buffer_ofs += prefix_len + entry->e_name_len + 1;
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册