diff mbox series

[RFC,-next,3/3] splice: Using scope-based resource instead of folio_lock/unlock

Message ID 20240826071036.2445717-4-lizetao1@huawei.com (mailing list archive)
State New
Headers show
Series fs: Introduce the scope-based resource management for folio_lock/unlock | expand

Commit Message

Li Zetao Aug. 26, 2024, 7:10 a.m. UTC
Use guard() to manage locking and unlocking a folio, thus avoiding the
use of goto unlock code. Remove the out_unlock and error label, and
return directly when an error occurs, allowing the compiler to release
the folio's lock.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 fs/splice.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 06232d7e505f..bf976f2edfc1 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -120,36 +120,25 @@  static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
 				       struct pipe_buffer *buf)
 {
 	struct folio *folio = page_folio(buf->page);
-	int err;
 
 	if (!folio_test_uptodate(folio)) {
-		folio_lock(folio);
+		guard(folio)(folio);
 
 		/*
 		 * Folio got truncated/unhashed. This will cause a 0-byte
 		 * splice, if this is the first page.
 		 */
-		if (!folio->mapping) {
-			err = -ENODATA;
-			goto error;
-		}
+		if (!folio->mapping)
+			return -ENODATA;
 
 		/*
 		 * Uh oh, read-error from disk.
 		 */
-		if (!folio_test_uptodate(folio)) {
-			err = -EIO;
-			goto error;
-		}
-
-		/* Folio is ok after all, we are done */
-		folio_unlock(folio);
+		if (!folio_test_uptodate(folio))
+			return -EIO;
 	}
 
 	return 0;
-error:
-	folio_unlock(folio);
-	return err;
 }
 
 const struct pipe_buf_operations page_cache_pipe_buf_ops = {