Commit 561fb35a authored by Bhanusree Pola's avatar Bhanusree Pola Committed by Greg Kroah-Hartman
Browse files

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: default avatarBhanusree Pola <bhanusreemahesh@gmail.com>
[ Gao Xiang: fix x != NULL comparision to x as well. ]
Signed-off-by: default avatarGao Xiang <gaoxiang25@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 51385436
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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) {
+3 −3
Original line number Diff line number Diff line
@@ -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();
	}
+1 −1
Original line number Diff line number Diff line
@@ -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)
+3 −3
Original line number Diff line number Diff line
@@ -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;

+1 −1
Original line number Diff line number Diff line
@@ -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);

Loading