Skip to contentSkip to conversation

ext4: Delete unnecessary checks before brelse()

PATCH Applied Markus Elfring 3 participants 3 messages Jun 13, 2020 – Aug 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Delete unnecessary checks before brelse()

From: Markus Elfring <[email protected]>
Date: Sat, 13 Jun 2020 19:12:24 +0200

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.

This issue was detected by using the Coccinelle software.

---
 fs/ext4/extents.c | 6 ++----
 fs/ext4/xattr.c   | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
fs/ext4/extents.c +2 -4
index 221f240eae60..315276d50aa8 100644
@@ -693,10 +693,8 @@ void ext4_ext_drop_refs(struct ext4_ext_path *path)
 		return;
 	depth = path->p_depth;
 	for (i = 0; i <= depth; i++, path++) {
-		if (path->p_bh) {
-			brelse(path->p_bh);
-			path->p_bh = NULL;
-		}
+		brelse(path->p_bh);
+		path->p_bh = NULL;
 	}
 }
 
fs/ext4/xattr.c +1 -2
index 9b29a40738ac..eb997ce21be3 100644
@@ -1354,8 +1354,7 @@ static int ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
 
 	block = 0;
 	while (wsize < bufsize) {
-		if (bh != NULL)
-			brelse(bh);
+		brelse(bh);
 		csize = (bufsize - wsize) > blocksize ? blocksize :
 								bufsize - wsize;
 		bh = ext4_getblk(handle, ea_inode, block, 0);

--
2.27.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 13 Jun 2020 19:12:24 +0200

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.

This issue was detected by using the Coccinelle software.

Sure, LGTM. Feel free to add

Quoted 39 lines
---
  fs/ext4/extents.c | 6 ++----
  fs/ext4/xattr.c   | 3 +--
  2 files changed, 3 insertions(+), 6 deletions(-)
fs/ext4/extents.c +2 -4
index 221f240eae60..315276d50aa8 100644
@@ -693,10 +693,8 @@ void ext4_ext_drop_refs(struct ext4_ext_path *path)
  		return;
  	depth = path->p_depth;
  	for (i = 0; i <= depth; i++, path++) {
-		if (path->p_bh) {
-			brelse(path->p_bh);
-			path->p_bh = NULL;
-		}
+		brelse(path->p_bh);
+		path->p_bh = NULL;
  	}
  }
 
fs/ext4/xattr.c +1 -3
index 9b29a40738ac..eb997ce21be3 100644
@@ -1354,8 +1354,7 @@ static int ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
 
  	block = 0;
  	while (wsize < bufsize) {
-		if (bh != NULL)
-			brelse(bh);
+		brelse(bh);
  		csize = (bufsize - wsize) > blocksize ? blocksize :
  								bufsize - wsize;
  		bh = ext4_getblk(handle, ea_inode, block, 0);
--

2.27.0