All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Staging: erofs: Use !x in place of NULL comparision
@ 2019-03-21 15:20 Bhanusree Pola
  2019-03-21 19:13 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Bhanusree Pola @ 2019-03-21 15:20 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Greg Kroah-Hartman, Gao Xiang, Chao Yu

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

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

diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 1cf1afe2d73a..ff83dbd8f27c 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -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) {
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index e3bfde00c7d2..828aa03a674f 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -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);
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 15c784fba879..a3aeb720e9ed 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -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);
diff --git a/drivers/staging/erofs/unzip_pagevec.h b/drivers/staging/erofs/unzip_pagevec.h
index 23856ba2742d..42b3bc21c0b4 100644
--- a/drivers/staging/erofs/unzip_pagevec.h
+++ b/drivers/staging/erofs/unzip_pagevec.h
@@ -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;
 
diff --git a/drivers/staging/erofs/xattr.c b/drivers/staging/erofs/xattr.c
index f716ab0446e5..c7b6bcaff53f 100644
--- a/drivers/staging/erofs/xattr.c
+++ b/drivers/staging/erofs/xattr.c
@@ -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;
 	}
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Staging: erofs: Use !x in place of NULL comparision
  2019-03-21 15:20 [PATCH v2] Staging: erofs: Use !x in place of NULL comparision Bhanusree Pola
@ 2019-03-21 19:13 ` Greg Kroah-Hartman
  2019-03-22  1:22   ` Gao Xiang
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-03-21 19:13 UTC (permalink / raw)
  To: Bhanusree Pola; +Cc: outreachy-kernel, Gao Xiang, Chao Yu

On Thu, Mar 21, 2019 at 08:50:07PM +0530, Bhanusree Pola wrote:
> 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>
> ---
> 
> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Staging: erofs: Use !x in place of NULL comparision
  2019-03-21 19:13 ` Greg Kroah-Hartman
@ 2019-03-22  1:22   ` Gao Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2019-03-22  1:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Bhanusree Pola; +Cc: outreachy-kernel, Chao Yu, Miao Xie



On 2019/3/22 3:13, Greg Kroah-Hartman wrote:
> On Thu, Mar 21, 2019 at 08:50:07PM +0530, Bhanusree Pola wrote:
>> 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>
>> ---
>>
>> 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 <vatsalanarang@gmail.com>
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

> 
> greg k-h
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-22  1:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-21 15:20 [PATCH v2] Staging: erofs: Use !x in place of NULL comparision Bhanusree Pola
2019-03-21 19:13 ` Greg Kroah-Hartman
2019-03-22  1:22   ` Gao Xiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.