mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nilfs2: delete unnecessary checks before brelse()
@ 2022-08-19  8:17 cgel.zte
  2022-08-19  8:42 ` Ryusuke Konishi
  2022-08-19 21:31 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: cgel.zte @ 2022-08-19  8:17 UTC (permalink / raw)
  To: konishi.ryusuke; +Cc: linux-nilfs, linux-kernel, Minghao Chi, Zeal Robot

From: Minghao Chi <chi.minghao@zte.com.cn>

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

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
 fs/nilfs2/btree.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index f544c22fff78..b3b5a46488c2 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -1668,8 +1668,7 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *btree, __u64 key)
 	maxkey = nilfs_btree_node_get_key(node, nchildren - 1);
 	nextmaxkey = (nchildren > 1) ?
 		nilfs_btree_node_get_key(node, nchildren - 2) : 0;
-	if (bh != NULL)
-		brelse(bh);
+	brelse(bh);
 
 	return (maxkey == key) && (nextmaxkey < NILFS_BMAP_LARGE_LOW);
 }
@@ -1717,8 +1716,7 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *btree,
 		ptrs[i] = le64_to_cpu(dptrs[i]);
 	}
 
-	if (bh != NULL)
-		brelse(bh);
+	brelse(bh);
 
 	return nitems;
 }
-- 
2.25.1

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

* Re: [PATCH] nilfs2: delete unnecessary checks before brelse()
  2022-08-19  8:17 [PATCH] nilfs2: delete unnecessary checks before brelse() cgel.zte
@ 2022-08-19  8:42 ` Ryusuke Konishi
  2022-08-19 21:31 ` David Laight
  1 sibling, 0 replies; 4+ messages in thread
From: Ryusuke Konishi @ 2022-08-19  8:42 UTC (permalink / raw)
  To: cgel.zte; +Cc: linux-nilfs, linux-kernel, Minghao Chi, Zeal Robot

On Fri, Aug 19, 2022 at 5:17 PM wrote:
>
> From: Minghao Chi <chi.minghao@zte.com.cn>
>
> The brelse() function tests whether its argument is NULL
> and then returns immediately.
> Thus remove the tests which are not needed around the shown calls.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
>  fs/nilfs2/btree.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Will apply, thanks!

Ryusuke Konishi

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

* RE: [PATCH] nilfs2: delete unnecessary checks before brelse()
  2022-08-19  8:17 [PATCH] nilfs2: delete unnecessary checks before brelse() cgel.zte
  2022-08-19  8:42 ` Ryusuke Konishi
@ 2022-08-19 21:31 ` David Laight
  2022-08-19 23:50   ` Ryusuke Konishi
  1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2022-08-19 21:31 UTC (permalink / raw)
  To: 'cgel.zte@gmail.com', konishi.ryusuke
  Cc: linux-nilfs, linux-kernel, Minghao Chi, Zeal Robot

From: cgel.zte@gmail.com
> Sent: 19 August 2022 09:17
> 
> The brelse() function tests whether its argument is NULL
> and then returns immediately.
> Thus remove the tests which are not needed around the shown calls.

The test is the caller makes sense if it is a 'hot' path
and bh is normally NULL.

	David

> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---
>  fs/nilfs2/btree.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
> index f544c22fff78..b3b5a46488c2 100644
> --- a/fs/nilfs2/btree.c
> +++ b/fs/nilfs2/btree.c
> @@ -1668,8 +1668,7 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *btree, __u64 key)
>  	maxkey = nilfs_btree_node_get_key(node, nchildren - 1);
>  	nextmaxkey = (nchildren > 1) ?
>  		nilfs_btree_node_get_key(node, nchildren - 2) : 0;
> -	if (bh != NULL)
> -		brelse(bh);
> +	brelse(bh);
> 
>  	return (maxkey == key) && (nextmaxkey < NILFS_BMAP_LARGE_LOW);
>  }
> @@ -1717,8 +1716,7 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *btree,
>  		ptrs[i] = le64_to_cpu(dptrs[i]);
>  	}
> 
> -	if (bh != NULL)
> -		brelse(bh);
> +	brelse(bh);
> 
>  	return nitems;
>  }
> --
> 2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] nilfs2: delete unnecessary checks before brelse()
  2022-08-19 21:31 ` David Laight
@ 2022-08-19 23:50   ` Ryusuke Konishi
  0 siblings, 0 replies; 4+ messages in thread
From: Ryusuke Konishi @ 2022-08-19 23:50 UTC (permalink / raw)
  To: David Laight; +Cc: cgel.zte, linux-nilfs, linux-kernel, Minghao Chi, Zeal Robot

Hi David,

On Sat, Aug 20, 2022 at 6:31 AM David Laight wrote:
>
> From: cgel.zte@gmail.com
> > Sent: 19 August 2022 09:17
> >
> > The brelse() function tests whether its argument is NULL
> > and then returns immediately.
> > Thus remove the tests which are not needed around the shown calls.
>

> The test is the caller makes sense if it is a 'hot' path
> and bh is normally NULL.
>
>         David

Should the commit message say "inline function" instead of "function"?

or do you have other intentions?

These tests indeed seem meaningless, since brelse() is an inline
function that tests whether bh is NULL or not, like this

 static inline void brelse(struct buffer_head *bh)
 {
        if (bh)
                __brelse(bh);
 }

and the corresponding parts are equivalent to:

  if (bh != NULL)
          if (bh)
                  __brelse(bh);


Regards,
Ryusuke Konishi

>
> >
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> > ---
> >  fs/nilfs2/btree.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
> > index f544c22fff78..b3b5a46488c2 100644
> > --- a/fs/nilfs2/btree.c
> > +++ b/fs/nilfs2/btree.c
> > @@ -1668,8 +1668,7 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *btree, __u64 key)
> >       maxkey = nilfs_btree_node_get_key(node, nchildren - 1);
> >       nextmaxkey = (nchildren > 1) ?
> >               nilfs_btree_node_get_key(node, nchildren - 2) : 0;
> > -     if (bh != NULL)
> > -             brelse(bh);
> > +     brelse(bh);
> >
> >       return (maxkey == key) && (nextmaxkey < NILFS_BMAP_LARGE_LOW);
> >  }
> > @@ -1717,8 +1716,7 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *btree,
> >               ptrs[i] = le64_to_cpu(dptrs[i]);
> >       }
> >
> > -     if (bh != NULL)
> > -             brelse(bh);
> > +     brelse(bh);
> >
> >       return nitems;
> >  }
> > --
> > 2.25.1

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

end of thread, other threads:[~2022-08-19 23:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-19  8:17 [PATCH] nilfs2: delete unnecessary checks before brelse() cgel.zte
2022-08-19  8:42 ` Ryusuke Konishi
2022-08-19 21:31 ` David Laight
2022-08-19 23:50   ` Ryusuke Konishi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®