Staging: erofs: Use !x in place of NULL comparision
PATCH v2 1/1 Staging: erofs: Use !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>
---
v2:
-modified commit log.
-All NULL comparisions in erofs are modified.
drivers/staging/erofs/inode.c | 4 ++-- drivers/staging/erofs/internal.h | 4 ++-- drivers/staging/erofs/super.c | 14 +++++++------- drivers/staging/erofs/unzip_pagevec.h | 4 ++-- drivers/staging/erofs/xattr.c | 12 ++++++------ 5 files changed, 19 insertions(+), 19 deletions(-)
drivers/staging/erofs/inode.c +2 -2
@@ -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;
@@ -264,7 +264,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 ) {
drivers/staging/erofs/internal.h +2 -2
@@ -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);
drivers/staging/erofs/super.c +7 -7
@@ -49,7 +49,7 @@ static struct inode *alloc_inode(struct super_block *sb)struct erofs_vnode *vi =kmem_cache_alloc (erofs_inode_cachep,GFP_KERNEL ); -if (vi ==NULL ) +if (!vi)return NULL ;/* zero out everything except vfs_inode */
@@ -86,7 +86,7 @@ static int superblock_read(struct super_block *sb) bh =sb_bread (sb,0 ); -if (bh ==NULL ) { +if (!bh) {errln ("cannot read erofs superblock" );return -EIO ; }
@@ -336,7 +336,7 @@ static struct inode *erofs_init_managed_cache(struct super_block *sb) {struct inode *inode =new_inode (sb); -if (unlikely (inode ==NULL )) +if (unlikely (!inode))return ERR_PTR (-ENOMEM );set_nlink (inode,1 );
@@ -367,7 +367,7 @@ static int erofs_read_super(struct super_block *sb, } sbi =kzalloc (sizeof (struct erofs_sb_info ),GFP_KERNEL ); -if (unlikely (sbi ==NULL )) { +if (unlikely (!sbi)) { err = -ENOMEM ; goto err; }
@@ -431,14 +431,14 @@ static int erofs_read_super(struct super_block *sb, } sb->s_root =d_make_root (inode); -if (sb->s_root ==NULL ) { +if (!sb->s_root) { err = -ENOMEM ; goto err_iget; }/* save the device name to sbi */ sbi->dev_name =__getname (); -if (sbi->dev_name ==NULL ) { +if (!sbi->dev_name) { err = -ENOMEM ; goto err_devname; }
@@ -481,7 +481,7 @@ static void erofs_put_super(struct super_block *sb)struct erofs_sb_info *sbi =EROFS_SB (sb);/* for cases which are failed in "read_super" */ -if (sbi ==NULL ) +if (!sbi)return ;WARN_ON (sb->s_magic !=EROFS_SUPER_MAGIC );
drivers/staging/erofs/unzip_pagevec.h +2 -2
@@ -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)
@@ -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;
drivers/staging/erofs/xattr.c +6 -6
@@ -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;
@@ -344,7 +344,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,
@@ -435,7 +435,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);
@@ -537,13 +537,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 !=NULL && !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 ; }
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerQuoted 25 lines · Bhanusree Pola
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\)(...));
(quoted diff) +1
-1-if(x==NULL) +if(!x)S
@@
expression e;
@@-e == NULL
+!e
// </smpl>
Quoted 6 lines
Signed-off-by Bhanusree Pola <[email protected]>---
v2:
-modified commit log.
-All NULL comparisions in erofs are modified.
This patch does not apply to my staging-testing branch. Please rebase it and resend, thanks.
greg k-h
Quoted 29 lines · Greg Kroah-Hartman
Quoted 28 lines · Bhanusree Pola
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\)(...));
(quoted diff) +1
-1-if(x==NULL) +if(!x)S
@@
expression e;
@@-e == NULL
+!e
// </smpl>Signed-off-by Bhanusree Pola <[email protected]>---
Quoted 6 lines
Quoted 3 lines
v2:
-modified commit log.
-All NULL comparisions in erofs are modified.This patch does not apply to my staging-testing branch. Please rebase it and resend, thanks.
opps, it seems that there is another new patch called
From e2ff9f15e8ac8861929573e4fa80bfe92e1b1805 Mon Sep 17 00:00:00 2001
From: Vatsala Narang <[email protected]>
Date: Thu, 21 Mar 2019 05:36:13 +0530
Subject: staging: erofs: Replace NULL comparisons
which has been merged recently, I will rebase the patch and clean up all NULL comparisions.
Thanks,
Gao Xiang
Quoted 3 lines
greg k-h