Skip to contentSkip to conversation

btrfs: remove dead assignment in prepare_one_folio()

PATCH Superseded Massimiliano Pellizzer 2 participants 3 messages Nov 28, 2025 – Dec 4, 2025 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

In the error path of prepare_one_folio(), 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).

The zero assignment is never observerd by any code path, therefore it can be safely removed.

No functional change.

---
 fs/btrfs/file.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/file.c +0 -1
index 7a501e73d880..7d875aa261d1 100644
@@ -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
#1 lore raw
Quoted 9 lines · Massimiliano Pellizzer

In the error path of prepare_one_folio(), 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).

The zero assignment is never observerd by any code path, therefore it can be safely removed.

No functional change.

This looks fine to me. But given the fact that we are setting ret = 0 before entering the again: loop, this code is maintaining that (unneeded) invariant. So I think we should remove both or neither.

I would lean towards removing both, but I don't feel strongly about it.

Thanks,
Boris

Quoted 21 lines
---
 fs/btrfs/file.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/file.c +0 -1
index 7a501e73d880..7d875aa261d1 100644
@@ -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
#2 lore raw
Quoted 12 lines · Boris Burkov
Quoted 9 lines · Massimiliano Pellizzer

In the error path of prepare_one_folio(), 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).

The zero assignment is never observerd by any code path, therefore it can be safely removed.

No functional change.

Quoted 9 lines

This looks fine to me. But given the fact that we are setting ret = 0 before entering the again: loop, this code is maintaining that (unneeded) invariant. So I think we should remove both or neither.

I would lean towards removing both, but I don't feel strongly about it.

Thanks,
Boris

Hi Boris,

Good point. You are right, both assignments serve no purpose since ret is immediately overwritten after the again label.

I'll send a v2 that removes both the initialization and the assignment before the goto.

Thanks for the review,
Massimiliano

Quoted 21 lines
Quoted 21 lines
---
 fs/btrfs/file.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/file.c +0 -2
index 7a501e73d880..7d875aa261d1 100644
@@ -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;
--

2.51.0