Skip to contentSkip to conversation

btrfs: remove dead assignment in prepare_one_folio()

PATCH In review Massimiliano Pellizzer 2 participants 2 messages Dec 4, 2025 – Dec 12, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: remove dead assignment in prepare_one_folio()

In prepare_one_folio(), ret is initialized to 0 at declaration, and in an error path we assign ret = 0 before jumping to the again label to retry the operation. However, ret is immediately overwritten by ret = set_folio_extent_mapped(folio) after the again label.

Both assignments are never observed by any code path, therefore they can be safely removed.

No functional change.

---
v2: Remove also the initial ret = 0 assignment for consistency

 fs/btrfs/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/file.c +1 -2
index 7a501e73d880..9e2c2f2cd03f 100644
@@ -859,7 +859,7 @@ static noinline int prepare_one_folio(struct inode *inode, struct folio **folio_
 	fgf_t fgp_flags = (nowait ? FGP_WRITEBEGIN | FGP_NOWAIT : FGP_WRITEBEGIN) |
 			  fgf_set_order(write_bytes);
 	struct folio *folio;
-	int ret = 0;
+	int ret;
 
 again:
 	folio = __filemap_get_folio(inode->i_mapping, index, fgp_flags, mask);
@@ -877,7 +877,6 @@ static noinline int prepare_one_folio(struct inode *inode, struct folio **folio_
 		/* The folio is already unlocked. */
 		folio_put(folio);
 		if (!nowait && ret == -EAGAIN) {
-			ret = 0;
 			goto again;
 		}
 		return ret;
Signature · 1 line
2.51.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Massimiliano Pellizzer

In prepare_one_folio(), ret is initialized to 0 at declaration, and in an error path we assign ret = 0 before jumping to the again label to retry the operation. However, ret is immediately overwritten by ret = set_folio_extent_mapped(folio) after the again label.

Both assignments are never observed by any code path, therefore they can be safely removed.

Right, if 'ret' was the loop invariant such explicit settings are good for readability but this is not the case.

Quoted 3 lines

No functional change.

Added to for-next, thanks.

Quoted 20 lines

---
v2: Remove also the initial ret = 0 assignment for consistency

 fs/btrfs/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/file.c +1 -1
index 7a501e73d880..9e2c2f2cd03f 100644
@@ -859,7 +859,7 @@ static noinline int prepare_one_folio(struct inode *inode, struct folio **folio_
 	fgf_t fgp_flags = (nowait ? FGP_WRITEBEGIN | FGP_NOWAIT : FGP_WRITEBEGIN) |
 			  fgf_set_order(write_bytes);
 	struct folio *folio;
-	int ret = 0;
+	int ret;
 
 again:
 	folio = __filemap_get_folio(inode->i_mapping, index, fgp_flags, mask);

fs/btrfs/file.c static noinline int prepare_one_folio(struct inode *inode, struct folio **folio_ · line 881

Quoted 6 lines
fs/btrfs/file.c +0 -1
@@ -877,7 +877,6 @@ static noinline int prepare_one_folio(struct inode *inode, struct folio **folio_
 		/* The folio is already unlocked. */
 		folio_put(folio);
 		if (!nowait && ret == -EAGAIN) {
-			ret = 0;
 			goto again;
 		}

Minor thing fixed here, a single statement 'if' should not have the { }.