Skip to contentSkip to conversation

staging: Use !x in place of NULL comparison

PATCH In review Payal Kshirsagar 2 participants 7 messages Mar 31, 2019 – Apr 1, 2019 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: Use !x in place of NULL comparison

Challenge suggested by coccinelle.
This patchset:
-Uses !x in place of NULL comparison.

Payal Kshirsagar (5):
staging: comedi: use !x in place of NULL comparison
staging: rtlwifi: use !x in place of NULL comparison
staging: erofs: super.c: use !x in place of NULL comparison
staging: erofs: xattr.c: use !x in place of NULL comparison
staging: erofs: inode.c: use !x in place of NULL comparison

 drivers/staging/comedi/drivers/tests/ni_routes_test.c |  2 +-
 drivers/staging/erofs/inode.c                         |  4 ++--
 drivers/staging/erofs/super.c                         | 14 +++++++-------
 drivers/staging/erofs/xattr.c                         | 10 +++++-----
 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c      |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 staging: comedi: use !x in place of NULL comparison

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/comedi/drivers/tests/ni_routes_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/comedi/drivers/tests/ni_routes_test.c +1 -1
index c6dc18f..f809051 100644
@@ -282,7 +282,7 @@ void test_ni_sort_device_routes(void)
 
 void test_ni_find_route_set(void)
 {
-	unittest(ni_find_route_set(bad_dest, &DR) == NULL,
+	unittest(!ni_find_route_set(bad_dest, &DR),
 		 "check for nonexistent route_set\n");
 	unittest(ni_find_route_set(dest0, &DR) == &DR.routes[0],
 		 "find first route_set\n");
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 staging: rtlwifi: use !x in place of NULL comparison

In reply to Payal Kshirsagar

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c +1 -1
index dbb11c2..e661fc7 100644
@@ -33,7 +33,7 @@ static const char *const gl_btc_wifi_freq_string[] = {
 
 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
 {
-	if (!btcoexist->binded || NULL == btcoexist->adapter)
+	if (!btcoexist->binded || !btcoexist->adapter)
 		return false;
 
 	return true;
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 staging: erofs: super.c: use !x in place of NULL comparison

In reply to Payal Kshirsagar

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/erofs/super.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/erofs/super.c +7 -7
index 15c784f..a3aeb72 100644
@@ -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);
Signature · 1 line
2.7.4
#5 lore raw

PATCH 4/5 staging: erofs: xattr.c: use !x in place of NULL comparison

In reply to Payal Kshirsagar

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/erofs/xattr.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/erofs/xattr.c +5 -5
index f716ab0..aecbbda 100644
@@ -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);
@@ -543,7 +543,7 @@ static int xattr_entrylist(struct xattr_iter *_it,
 	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.7.4
#6 lore raw

PATCH 5/5 staging: erofs: inode.c: use !x in place of NULL comparison

In reply to Payal Kshirsagar

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/erofs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/erofs/inode.c +2 -2
index 924b8df..90d6aa3 100644
@@ -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) {
Signature · 1 line
2.7.4
#4 lore raw

Re: [Outreachy kernel] [PATCH 3/5] staging: erofs: super.c: use !x in place of NULL comparison

In reply to Payal Kshirsagar
Quoted 7 lines · Payal Kshirsagar

Challenge suggested by coccinelle.
Avoid NULL comparison, compare using boolean operator.

---
 drivers/staging/erofs/super.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

These 3 erofs patches are already changed in my tree and do not apply at all. Be sure you are always working against the correct tree and branch.

thanks,

greg k-h