2019-09-03 17:23:53

by Markus Elfring

[permalink] [raw]
Subject: [PATCH] fs/qnx: Delete unnecessary checks before brelse()

From: Markus Elfring <[email protected]>
Date: Tue, 3 Sep 2019 19:15:09 +0200

The brelse() function tests whether its argument is NULL
and then returns immediately.
Thus the tests around the shown calls are not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
fs/qnx4/inode.c | 3 +--
fs/qnx6/inode.c | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index e8da1cde87b9..018a4c657f7c 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -118,8 +118,7 @@ unsigned long qnx4_block_map( struct inode *inode, long iblock )
bh = NULL;
}
}
- if ( bh )
- brelse( bh );
+ brelse(bh);
}

QNX4DEBUG((KERN_INFO "qnx4: mapping block %ld of inode %ld = %ld\n",iblock,inode->i_ino,block));
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
index 345db56c98fd..083170541add 100644
--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -472,10 +472,8 @@ static int qnx6_fill_super(struct super_block *s, void *data, int silent)
out1:
iput(sbi->inodes);
out:
- if (bh1)
- brelse(bh1);
- if (bh2)
- brelse(bh2);
+ brelse(bh1);
+ brelse(bh2);
outnobh:
kfree(qs);
s->s_fs_info = NULL;
--
2.23.0


2019-09-03 17:28:38

by Anders Larsen

[permalink] [raw]
Subject: Re: [PATCH] fs/qnx: Delete unnecessary checks before brelse()

On Tuesday, 2019-09-03 19:20 Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Tue, 3 Sep 2019 19:15:09 +0200
>
> The brelse() function tests whether its argument is NULL
> and then returns immediately.
> Thus the tests around the shown calls are not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> fs/qnx4/inode.c | 3 +--
> fs/qnx6/inode.c | 6 ++----
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
> index e8da1cde87b9..018a4c657f7c 100644
> --- a/fs/qnx4/inode.c
> +++ b/fs/qnx4/inode.c
> @@ -118,8 +118,7 @@ unsigned long qnx4_block_map( struct inode *inode, long iblock )
> bh = NULL;
> }
> }
> - if ( bh )
> - brelse( bh );
> + brelse(bh);
> }
>
> QNX4DEBUG((KERN_INFO "qnx4: mapping block %ld of inode %ld = %ld\n",iblock,inode->i_ino,block));
> diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
> index 345db56c98fd..083170541add 100644
> --- a/fs/qnx6/inode.c
> +++ b/fs/qnx6/inode.c
> @@ -472,10 +472,8 @@ static int qnx6_fill_super(struct super_block *s, void *data, int silent)
> out1:
> iput(sbi->inodes);
> out:
> - if (bh1)
> - brelse(bh1);
> - if (bh2)
> - brelse(bh2);
> + brelse(bh1);
> + brelse(bh2);
> outnobh:
> kfree(qs);
> s->s_fs_info = NULL;

Acked-by: Anders Larsen <[email protected]>




2019-09-04 14:59:11

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] fs/qnx: Delete unnecessary checks before brelse()

On Tue, Sep 03, 2019 at 07:27:22PM +0200, Anders Larsen wrote:
> On Tuesday, 2019-09-03 19:20 Markus Elfring wrote:
> > diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
> > index 345db56c98fd..083170541add 100644
> > --- a/fs/qnx6/inode.c
> > +++ b/fs/qnx6/inode.c
> > @@ -472,10 +472,8 @@ static int qnx6_fill_super(struct super_block *s, void *data, int silent)
> > out1:
> > iput(sbi->inodes);
> > out:
> > - if (bh1)
> > - brelse(bh1);
> > - if (bh2)
> > - brelse(bh2);
> > + brelse(bh1);
> > + brelse(bh2);
> > outnobh:
> > kfree(qs);
> > s->s_fs_info = NULL;

It looks like the original code is buggy:

fs/qnx6/inode.c
409 pr_info("superblock #1 active\n");
410 } else {
411 /* superblock #2 active */
412 sbi->sb_buf = bh2;
413 sbi->sb = (struct qnx6_super_block *)bh2->b_data;
414 brelse(bh1);
^^^^^^^^^^
brelse()

415 pr_info("superblock #2 active\n");
416 }
417 mmi_success:
418 /* sanity check - limit maximum indirect pointer levels */
419 if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
420 pr_err("too many inode levels (max %i, sb %i)\n",
421 QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
422 goto out;
^^^^^^^^
goto

423 }

[ snip ]

466
467 out3:
468 dput(s->s_root);
469 s->s_root = NULL;
470 out2:
471 iput(sbi->longfile);
472 out1:
473 iput(sbi->inodes);
474 out:
475 if (bh1)
476 brelse(bh1);
^^^^^^^^^^^
Double brelse().

477 if (bh2)
478 brelse(bh2);
479 outnobh:
480 kfree(qs);
481 s->s_fs_info = NULL;
482 return ret;
483 }

regards,
dan carpenter