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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 fs/splice.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

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 = {
-- 
2.34.1





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux