2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-19 02:34:01 +08:00

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: Bhanusree Pola <bhanusreemahesh@gmail.com>
[ Gao Xiang: fix x != NULL comparision to x as well. ]
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Bhanusree Pola 2019-03-22 10:38:16 +08:00 committed by Greg Kroah-Hartman
parent 51385436f1
commit 561fb35a9d
6 changed files with 18 additions and 18 deletions

View File

@ -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,
{ {
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) {

View File

@ -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,
} }
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)
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();
} }

View File

@ -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)

View File

@ -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,
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,
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;

View File

@ -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);

View File

@ -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)
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,
* 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,
/* 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,
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,
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,
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;
} }