Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: viro@zeniv.linux.org.uk, axboe@kernel.dk,
	zohar@linux.vnet.ibm.com, mcgrof@kernel.org,
	keescook@chromium.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/2] fs: avoid fdput() after failed fdget() in ksys_sync_file_range()
Date: Wed, 13 May 2020 17:33:20 -0600	[thread overview]
Message-ID: <5945f42e08ee037c4d1d0492622defb5904f4850.1589411496.git.skhan@linuxfoundation.org> (raw)
In-Reply-To: <cover.1589411496.git.skhan@linuxfoundation.org>

Fix ksys_sync_file_range() to avoid fdput() after a failed fdget().
fdput() doesn't do fput() on this file since FDPUT_FPUT isn't set
in fd.flags.

Change it anyway since failed fdget() doesn't require a fdput(). Refine
the code path a bit for it to read more clearly.
Reference: 22f96b3808c1 ("fs: add sync_file_range() helper")

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
 fs/sync.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/sync.c b/fs/sync.c
index 4d1ff010bc5a..3ec312bf62eb 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -365,14 +365,14 @@ int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
 			 unsigned int flags)
 {
 	int ret;
-	struct fd f;
+	struct fd f = fdget(fd);
 
-	ret = -EBADF;
-	f = fdget(fd);
-	if (f.file)
-		ret = sync_file_range(f.file, offset, nbytes, flags);
+	if (!f.file)
+		return -EBADF;
 
+	ret = sync_file_range(f.file, offset, nbytes, flags);
 	fdput(f);
+
 	return ret;
 }
 
-- 
2.25.1


  reply	other threads:[~2020-05-13 23:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 23:33 [PATCH v3 0/2] fs: avoid fdput() after failed fdget() Shuah Khan
2020-05-13 23:33 ` Shuah Khan [this message]
2020-05-15 16:12   ` [PATCH v3 1/2] fs: avoid fdput() after failed fdget() in ksys_sync_file_range() Luis Chamberlain
2020-05-13 23:33 ` [PATCH v3 2/2] fs: avoid fdput() after failed fdget() in kernel_read_file_from_fd() Shuah Khan
2020-05-15 19:22   ` Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5945f42e08ee037c4d1d0492622defb5904f4850.1589411496.git.skhan@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.vnet.ibm.com \
    --subject='Re: [PATCH v3 1/2] fs: avoid fdput() after failed fdget() in ksys_sync_file_range()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).