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 <hch@lst.de> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
9d4b74aee8
commit
27eb11c963
19
fs/utimes.c
19
fs/utimes.c
|
@ -23,14 +23,19 @@ static int utimes_common(const struct path *path, struct timespec64 *times)
|
||||||
struct inode *inode = path->dentry->d_inode;
|
struct inode *inode = path->dentry->d_inode;
|
||||||
struct inode *delegated_inode = NULL;
|
struct inode *delegated_inode = 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;
|
||||||
|
}
|
||||||
|
|
||||||
error = mnt_want_write(path->mnt);
|
error = mnt_want_write(path->mnt);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (times && times[0].tv_nsec == UTIME_NOW &&
|
|
||||||
times[1].tv_nsec == UTIME_NOW)
|
|
||||||
times = NULL;
|
|
||||||
|
|
||||||
newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
|
newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
|
||||||
if (times) {
|
if (times) {
|
||||||
if (times[0].tv_nsec == UTIME_OMIT)
|
if (times[0].tv_nsec == UTIME_OMIT)
|
||||||
|
@ -76,9 +81,6 @@ static int do_utimes_path(int dfd, const char __user *filename,
|
||||||
struct path path;
|
struct path path;
|
||||||
int lookup_flags = 0, error;
|
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))
|
if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -107,9 +109,6 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
|
||||||
struct fd f;
|
struct fd f;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (times &&
|
|
||||||
(!nsec_valid(times[0].tv_nsec) || !nsec_valid(times[1].tv_nsec)))
|
|
||||||
return -EINVAL;
|
|
||||||
if (flags)
|
if (flags)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue