[PATCH 6.18 100/396] netfs: release readahead folios on iterator preparation failure

Greg Kroah-Hartman <[email protected]> Fri, 7 Aug 2026 16:34:20 +0200
Newsgroups gmane.linux.kernel.stable,gmane.linux.file-systems
Message-ID <[email protected]>
6.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Yichong Chen <[email protected]>

[ Upstream commit 87eb3d272dcbcbbfe5c1576c10e5dc72810cf1f6 ]

netfs_prepare_read_iterator() batches readahead folios in put_batch so that
the folio references can be dropped after the I/O iterator has been
prepared.

If rolling_buffer_load_from_ra() fails after earlier folios have been
batched, the function returns immediately and leaves those references held.
Release the batch before returning the error.

Fixes: 06fa229ceb36 ("netfs: Abstract out a rolling folio buffer implementation")
Signed-off-by: Yichong Chen <[email protected]>
Signed-off-by: David Howells <[email protected]>
Link: https://patch.msgid.link/[email protected]
cc: Paulo Alcantara <[email protected]>
cc: [email protected]
cc: [email protected]
Signed-off-by: Christian Brauner (Amutable) <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
 fs/netfs/buffered_read.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index fab3181c7f869..221287f8925a9 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -102,8 +102,10 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq,
 
 			added = rolling_buffer_load_from_ra(&rreq->buffer, ractl,
 							    &put_batch);
-			if (added < 0)
+			if (added < 0) {
+				folio_batch_release(&put_batch);
 				return added;
+			}
 			rreq->submitted += added;
 		}
 		folio_batch_release(&put_batch);
-- 
2.53.0