Skip to contentSkip to conversation

ocfs2: remove redundant NULL check in rename path

PATCH Applied Long Li 3 participants 3 messages Jun 17, 2025 OCFS2

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH 1/1 ocfs2: remove redundant NULL check in rename path

The code checks newfe_bh for NULL after it has already been dereferenced to access b_data. This NULL check is unnecessary for two reasons:

1. If ocfs2_inode_lock() succeeds (returns >= 0), newfe_bh is guaranteed to be valid.
2. We've already dereferenced newfe_bh to access b_data, so it must be non-NULL at this point.

Remove the redundant NULL check in the trace_ocfs2_rename_over_existing() call to improve code clarity.

---
 fs/ocfs2/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/namei.c +2 -2
index 99278c8f0e24..26bc59c3a813 100644
@@ -1452,8 +1452,8 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
 		newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
 
 		trace_ocfs2_rename_over_existing(
-		     (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
-		     (unsigned long long)newfe_bh->b_blocknr : 0ULL);
+		     (unsigned long long)newfe_blkno, newfe_bh,
+		     (unsigned long long)newfe_bh->b_blocknr);
 
 		if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) {
 			status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Long Li

The code checks newfe_bh for NULL after it has already been dereferenced to access b_data. This NULL check is unnecessary for two reasons:

1. If ocfs2_inode_lock() succeeds (returns >= 0), newfe_bh is guaranteed to be valid.
2. We've already dereferenced newfe_bh to access b_data, so it must be non-NULL at this point.

Quoted 5 lines

Remove the redundant NULL check in the trace_ocfs2_rename_over_existing() call to improve code clarity.

Quoted 21 lines
---
 fs/ocfs2/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/namei.c +2 -2
index 99278c8f0e24..26bc59c3a813 100644
@@ -1452,8 +1452,8 @@ static int ocfs2_rename(struct mnt_idmap 
 *idmap,
 		newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
 
 		trace_ocfs2_rename_over_existing(
-		     (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
-		     (unsigned long long)newfe_bh->b_blocknr : 0ULL);
+		     (unsigned long long)newfe_blkno, newfe_bh,
+		     (unsigned long long)newfe_bh->b_blocknr);
 
 		if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 

1)) {
status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Long Li
Quoted 11 lines · Long Li

The code checks newfe_bh for NULL after it has already been dereferenced to access b_data. This NULL check is unnecessary for two reasons:

1. If ocfs2_inode_lock() succeeds (returns >= 0), newfe_bh is guaranteed to be valid.
2. We've already dereferenced newfe_bh to access b_data, so it must be non-NULL at this point.

Remove the redundant NULL check in the trace_ocfs2_rename_over_existing() call to improve code clarity.

Looks reasonable.

Quoted 20 lines
---
 fs/ocfs2/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/namei.c +2 -2
index 99278c8f0e24..26bc59c3a813 100644
@@ -1452,8 +1452,8 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
 		newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
 
 		trace_ocfs2_rename_over_existing(
-		     (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
-		     (unsigned long long)newfe_bh->b_blocknr : 0ULL);
+		     (unsigned long long)newfe_blkno, newfe_bh,
+		     (unsigned long long)newfe_bh->b_blocknr);
 
 		if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) {
 			status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,