diff mbox series

nfs: Add missing release on error in nfs_lock_and_join_requests()

Message ID 3aaaa3d5-1c8a-41e4-98c7-717801ddd171@stanley.mountain (mailing list archive)
State Handled Elsewhere
Headers show
Series nfs: Add missing release on error in nfs_lock_and_join_requests() | expand

Commit Message

Dan Carpenter April 2, 2025, 11:02 a.m. UTC
Call nfs_release_request() on this error path before returning.

Fixes: c3f2235782c3 ("nfs: fold nfs_folio_find_and_lock_request into nfs_lock_and_join_requests")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis and untested.  Pretty sure it's correct, though.  ;)

 fs/nfs/write.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Trond Myklebust April 2, 2025, 1:56 p.m. UTC | #1
On Wed, 2025-04-02 at 14:02 +0300, Dan Carpenter wrote:
> Call nfs_release_request() on this error path before returning.
> 
> Fixes: c3f2235782c3 ("nfs: fold nfs_folio_find_and_lock_request into
> nfs_lock_and_join_requests")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis and untested.  Pretty sure it's correct,
> though.  ;)
> 
>  fs/nfs/write.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/write.c b/fs/nfs/write.c
> index aa3d8bea3ec0..23df8b214474 100644
> --- a/fs/nfs/write.c
> +++ b/fs/nfs/write.c
> @@ -579,8 +579,10 @@ static struct nfs_page
> *nfs_lock_and_join_requests(struct folio *folio)
>  
>  	while (!nfs_lock_request(head)) {
>  		ret = nfs_wait_on_request(head);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			nfs_release_request(head);
>  			return ERR_PTR(ret);
> +		}
>  	}
>  
>  	/* Ensure that nobody removed the request before we locked
> it */

Yep, that's a slam dunk. Thanks for spotting it!
Christoph Hellwig April 3, 2025, 4:35 a.m. UTC | #2
On Wed, Apr 02, 2025 at 02:02:40PM +0300, Dan Carpenter wrote:
> Call nfs_release_request() on this error path before returning.
> 
> Fixes: c3f2235782c3 ("nfs: fold nfs_folio_find_and_lock_request into nfs_lock_and_join_requests")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index aa3d8bea3ec0..23df8b214474 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -579,8 +579,10 @@  static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
 
 	while (!nfs_lock_request(head)) {
 		ret = nfs_wait_on_request(head);
-		if (ret < 0)
+		if (ret < 0) {
+			nfs_release_request(head);
 			return ERR_PTR(ret);
+		}
 	}
 
 	/* Ensure that nobody removed the request before we locked it */