Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Al Viro <viro@zeniv.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] fs: move timespec validation into utimes_common
Date: Wed, 15 Jul 2020 08:54:32 +0200	[thread overview]
Message-ID: <20200715065434.2550-3-hch@lst.de> (raw)
In-Reply-To: <20200715065434.2550-1-hch@lst.de>

Consolidate the validation of the timespec from the two callers into
utimes_common.  That means it is done a little later (e.g. after the
path lookup), but I can't find anything that requires a specific
order of processing the errors.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/utimes.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/fs/utimes.c b/fs/utimes.c
index c667517b6eb110..441c7fb54053ca 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -27,9 +27,14 @@ static int utimes_common(const struct path *path, struct timespec64 *times)
 	if (error)
 		goto out;
 
-	if (times && times[0].tv_nsec == UTIME_NOW &&
-		     times[1].tv_nsec == UTIME_NOW)
-		times = NULL;
+	if (times) {
+		if (!nsec_valid(times[0].tv_nsec) ||
+		    !nsec_valid(times[1].tv_nsec))
+			return -EINVAL;
+		if (times[0].tv_nsec == UTIME_NOW &&
+		    times[1].tv_nsec == UTIME_NOW)
+			times = NULL;
+	}
 
 	newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
 	if (times) {
@@ -76,9 +81,6 @@ static int do_utimes_path(int dfd, const char __user *filename,
 	struct path path;
 	int lookup_flags = 0, error;
 
-	if (times &&
-	    (!nsec_valid(times[0].tv_nsec) || !nsec_valid(times[1].tv_nsec)))
-		return -EINVAL;
 	if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
 		return -EINVAL;
 
@@ -107,9 +109,6 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
 	struct fd f;
 	int error;
 
-	if (times &&
-	    (!nsec_valid(times[0].tv_nsec) || !nsec_valid(times[1].tv_nsec)))
-		return -EINVAL;
 	if (flags)
 		return -EINVAL;
 
-- 
2.27.0


  parent reply	other threads:[~2020-07-15  6:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-15  6:54 clean up utimes and use path based utimes in initrams Christoph Hellwig
2020-07-15  6:54 ` [PATCH 1/4] fs: refactor do_utimes Christoph Hellwig
2020-07-15  6:54 ` Christoph Hellwig [this message]
2020-07-15  6:54 ` [PATCH 3/4] fs: expose utimes_common Christoph Hellwig
2020-07-15  6:54 ` [PATCH 4/4] initramfs: use vfs_utimes in do_copy Christoph Hellwig
2020-07-15 17:03 ` clean up utimes and use path based utimes in initrams Linus Torvalds

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=20200715065434.2550-3-hch@lst.de \
    --to=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH 2/4] fs: move timespec validation into utimes_common' \
    /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).