lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240826071036.2445717-4-lizetao1@huawei.com>
Date: Mon, 26 Aug 2024 15:10:36 +0800
From: Li Zetao <lizetao1@...wei.com>
To: <viro@...iv.linux.org.uk>, <brauner@...nel.org>, <jack@...e.cz>,
	<willy@...radead.org>, <akpm@...ux-foundation.org>
CC: <lizetao1@...wei.com>, <linux-fsdevel@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <linux-mm@...ck.org>
Subject: [RFC PATCH -next 3/3] splice: Using scope-based resource instead of folio_lock/unlock

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@...wei.com>
---
 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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ