Skip to content

Commit 27eb11c

Browse files
author
Christoph Hellwig
committed
fs: move timespec validation into utimes_common
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 <[email protected]> Acked-by: Linus Torvalds <[email protected]>
1 parent 9d4b74a commit 27eb11c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

fs/utimes.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ static int utimes_common(const struct path *path, struct timespec64 *times)
2323
struct inode *inode = path->dentry->d_inode;
2424
struct inode *delegated_inode = NULL;
2525

26+
if (times) {
27+
if (!nsec_valid(times[0].tv_nsec) ||
28+
!nsec_valid(times[1].tv_nsec))
29+
return -EINVAL;
30+
if (times[0].tv_nsec == UTIME_NOW &&
31+
times[1].tv_nsec == UTIME_NOW)
32+
times = NULL;
33+
}
34+
2635
error = mnt_want_write(path->mnt);
2736
if (error)
2837
goto out;
2938

30-
if (times && times[0].tv_nsec == UTIME_NOW &&
31-
times[1].tv_nsec == UTIME_NOW)
32-
times = NULL;
33-
3439
newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
3540
if (times) {
3641
if (times[0].tv_nsec == UTIME_OMIT)
@@ -76,9 +81,6 @@ static int do_utimes_path(int dfd, const char __user *filename,
7681
struct path path;
7782
int lookup_flags = 0, error;
7883

79-
if (times &&
80-
(!nsec_valid(times[0].tv_nsec) || !nsec_valid(times[1].tv_nsec)))
81-
return -EINVAL;
8284
if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
8385
return -EINVAL;
8486

@@ -107,9 +109,6 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
107109
struct fd f;
108110
int error;
109111

110-
if (times &&
111-
(!nsec_valid(times[0].tv_nsec) || !nsec_valid(times[1].tv_nsec)))
112-
return -EINVAL;
113112
if (flags)
114113
return -EINVAL;
115114

0 commit comments

Comments
 (0)