]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: erofs: Use !x or x in place of NULL comparision
authorBhanusree Pola <bhanusreemahesh@gmail.com>
Fri, 22 Mar 2019 02:38:16 +0000 (10:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Mar 2019 14:20:25 +0000 (15:20 +0100)
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>
drivers/staging/erofs/inode.c
drivers/staging/erofs/internal.h
drivers/staging/erofs/super.c
drivers/staging/erofs/unzip_pagevec.h
drivers/staging/erofs/utils.c
drivers/staging/erofs/xattr.c

index 2df096afe91f4857287a03895a5ff6743fbc98dc..c7d3b815a798320292f23d718520beedb68c8e3b 100644 (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) {
                char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL);
 
-               if (unlikely(lnk == NULL))
+               if (unlikely(!lnk))
                        return -ENOMEM;
 
                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);
 
-       if (unlikely(inode == NULL))
+       if (unlikely(!inode))
                return ERR_PTR(-ENOMEM);
 
        if (inode->i_state & I_NEW) {
index e3bfde00c7d2030963204d3f62a10a798b03c964..1286b98ffd0aec836ed86a7f7724c31445109113 100644 (file)
@@ -469,7 +469,7 @@ erofs_grab_bio(struct super_block *sb,
        do {
                if (nr_pages == 1) {
                        bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1);
-                       if (unlikely(bio == NULL)) {
+                       if (unlikely(!bio)) {
                                DBG_BUGON(nofail);
                                return ERR_PTR(-ENOMEM);
                        }
@@ -477,7 +477,7 @@ erofs_grab_bio(struct super_block *sb,
                }
                bio = bio_alloc(gfp, nr_pages);
                nr_pages /= 2;
-       } while (unlikely(bio == NULL));
+       } while (unlikely(!bio));
 
        bio->bi_end_io = endio;
        bio_set_dev(bio, sb->s_bdev);
@@ -565,7 +565,7 @@ static inline void *erofs_vmap(struct page **pages, unsigned int count)
        while (1) {
                void *addr = vm_map_ram(pages, count, -1, PAGE_KERNEL);
                /* retry two more times (totally 3 times) */
-               if (addr != NULL || ++i >= 3)
+               if (addr || ++i >= 3)
                        return addr;
                vm_unmap_aliases();
        }
index 40766519b443639cb456496f3ac5fcf0e47c9b4e..7b460a3ca4d6e58b6ee282a1cac463c5d32e7e6f 100644 (file)
@@ -240,7 +240,7 @@ static int parse_options(struct super_block *sb, char *options)
        if (!options)
                return 0;
 
-       while ((p = strsep(&options, ",")) != NULL) {
+       while ((p = strsep(&options, ","))) {
                int token;
 
                if (!*p)
index 23856ba2742d882dd76ef6864ba09f6ad4d449f4..f37d8fd147717709ff59692629513113bf0bec59 100644 (file)
@@ -43,7 +43,7 @@ struct z_erofs_pagevec_ctor {
 static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor,
                                             bool atomic)
 {
-       if (ctor->curr == NULL)
+       if (!ctor->curr)
                return;
 
        if (atomic)
@@ -59,7 +59,7 @@ z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
        unsigned index;
 
        /* keep away from occupied pages */
-       if (ctor->next != NULL)
+       if (ctor->next)
                return ctor->next;
 
        for (index = 0; index < nr; ++index) {
@@ -121,7 +121,7 @@ z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor,
                             bool *occupied)
 {
        *occupied = false;
-       if (unlikely(ctor->next == NULL && type))
+       if (unlikely(!ctor->next && type))
                if (ctor->index + 1 == ctor->nr)
                        return false;
 
index f1725c2c45eaaaefcf7684408ac829d27a1bb0f3..3e7d30b6de1d20fa8abaf9120a2547b35f54e007 100644 (file)
@@ -61,7 +61,7 @@ struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
 repeat:
        rcu_read_lock();
        grp = radix_tree_lookup(&sbi->workstn_tree, index);
-       if (grp != NULL) {
+       if (grp) {
                *tag = xa_pointer_tag(grp);
                grp = xa_untag_pointer(grp);
 
index 3fa825672ce33710798e2265585a6b55de73b197..df40654b9fbbb7d4a5e46945fcbfe851a1cd04c9 100644 (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)
 {
-       if (it->page == NULL)
+       if (!it->page)
                return;
 
        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_xattrs = kmalloc_array(vi->xattr_shared_count,
                                                sizeof(uint), GFP_KERNEL);
-       if (vi->xattr_shared_xattrs == NULL) {
+       if (!vi->xattr_shared_xattrs) {
                xattr_iter_end(&it, atomic_map);
                ret = -ENOMEM;
                goto out_unlock;
@@ -235,7 +235,7 @@ static int xattr_foreach(struct xattr_iter *it,
         *    therefore entry should be in the page
         */
        entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
-       if (tlimit != NULL) {
+       if (tlimit) {
                unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry);
 
                BUG_ON(*tlimit < entry_sz);
@@ -282,7 +282,7 @@ static int xattr_foreach(struct xattr_iter *it,
        /* 3. handle xattr value */
        processed = 0;
 
-       if (op->alloc_buffer != NULL) {
+       if (op->alloc_buffer) {
                err = op->alloc_buffer(it, value_sz);
                if (err) {
                        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;
 
        it->buffer_size = value_sz;
-       return it->buffer == NULL ? 1 : err;
+       return !it->buffer ? 1 : err;
 }
 
 static void xattr_copyvalue(struct xattr_iter *_it,
@@ -437,7 +437,7 @@ int erofs_getxattr(struct inode *inode, int index,
        int ret;
        struct getxattr_iter it;
 
-       if (unlikely(name == NULL))
+       if (unlikely(!name))
                return -EINVAL;
 
        ret = init_inode_xattrs(inode);
@@ -539,13 +539,13 @@ static int xattr_entrylist(struct xattr_iter *_it,
        const struct xattr_handler *h =
                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;
 
        prefix = xattr_prefix(h);
        prefix_len = strlen(prefix);
 
-       if (it->buffer == NULL) {
+       if (!it->buffer) {
                it->buffer_ofs += prefix_len + entry->e_name_len + 1;
                return 1;
        }