netfs_retry_read_subrequests() treats ->prepare_read() as optional in the renegotiation loop, but calls it unconditionally when the retry has to allocate additional subrequests for the remaining range. Filesystems such as 9p, AFS and NFS do not provide ->prepare_read(), and Documentation/filesystems/netfs_library.rst documents the callback as optional, so a retry that runs with an active cache and a range larger than the remaining subrequests calls a NULL function pointer. Guard the allocation path the same way as the renegotiation path: skip the callback when the filesystem does not provide it and keep the error value zero so the retry proceeds with the negotiated stream limits. Found with smatch and confirmed by reading the call sites and the netfs documentation. The change was prepared with an AI coding assistant and compile-tested with W=1. No runtime reproducer was produced: it needs a netfs filesystem without ->prepare_read() (9p/AFS/NFS) with an active fscache cache and a retry that outgrows the existing subrequests. Fixes: e2d46f2ec332 ("netfs: Change the read result collector to only use one work item") Cc: stable@vger.kernel.org Signed-off-by: 王宇哲 --- fs/netfs/read_retry.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c index bfaaebe..0147931 100644 --- a/fs/netfs/read_retry.c +++ b/fs/netfs/read_retry.c @@ -225,7 +225,9 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs); netfs_stat(&netfs_n_rh_download); - ret = rreq->netfs_ops->prepare_read(subreq); + ret = 0; + if (rreq->netfs_ops->prepare_read) + ret = rreq->netfs_ops->prepare_read(subreq); if (ret < 0) { subreq->error = ret; trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed); -- 2.43.0