diff mbox

vfs: constify arguments to utime family of system calls

Message ID 1456809609-29137-1-git-send-email-ebiggers3@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Biggers March 1, 2016, 5:20 a.m. UTC
The system calls to set file times: utime(), utimes(), futimesat(), and
utimensat(), all take in pointers to a filename and time information,
neither of which is modified.  Mark the pointed-to data as 'const' to
better reflect the semantics.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
---
 arch/alpha/kernel/osf_sys.c |  2 +-
 fs/compat.c                 | 13 +++++++++----
 fs/utimes.c                 | 17 +++++++++--------
 include/linux/compat.h      |  8 ++++----
 include/linux/syscalls.h    | 12 ++++++------
 include/linux/time.h        |  3 ++-
 6 files changed, 31 insertions(+), 24 deletions(-)

Comments

kernel test robot March 1, 2016, 5:31 a.m. UTC | #1
Hi Eric,

[auto build test WARNING on tip/timers/core]
[also build test WARNING on v4.5-rc6 next-20160229]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Eric-Biggers/vfs-constify-arguments-to-utime-family-of-system-calls/20160301-132301
config: alpha-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=alpha 

All warnings (new ones prefixed by >>):

   arch/alpha/kernel/osf_sys.c: In function 'SYSC_osf_utimes':
>> arch/alpha/kernel/osf_sys.c:1074:7: warning: passing argument 2 of 'get_tv32' discards 'const' qualifier from pointer target type
      if (get_tv32(&ktvs[0], &tvs[0]) ||
          ^
   arch/alpha/kernel/osf_sys.c:955:1: note: expected 'struct timeval32 *' but argument is of type 'const struct timeval32 *'
    get_tv32(struct timeval *o, struct timeval32 __user *i)
    ^
   arch/alpha/kernel/osf_sys.c:1075:7: warning: passing argument 2 of 'get_tv32' discards 'const' qualifier from pointer target type
          get_tv32(&ktvs[1], &tvs[1]))
          ^
   arch/alpha/kernel/osf_sys.c:955:1: note: expected 'struct timeval32 *' but argument is of type 'const struct timeval32 *'
    get_tv32(struct timeval *o, struct timeval32 __user *i)
    ^

vim +1074 arch/alpha/kernel/osf_sys.c

^1da177e Linus Torvalds 2005-04-16  1058  		return error;
^1da177e Linus Torvalds 2005-04-16  1059  
^1da177e Linus Torvalds 2005-04-16  1060  	if (put_it32(out, &kout))
^1da177e Linus Torvalds 2005-04-16  1061  		return -EFAULT;
^1da177e Linus Torvalds 2005-04-16  1062  
^1da177e Linus Torvalds 2005-04-16  1063  	return 0;
^1da177e Linus Torvalds 2005-04-16  1064  
^1da177e Linus Torvalds 2005-04-16  1065  }
^1da177e Linus Torvalds 2005-04-16  1066  
c7887325 David Howells  2010-08-11  1067  SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
ec284566 Eric Biggers   2016-02-29  1068  		const struct timeval32 __user *, tvs)
^1da177e Linus Torvalds 2005-04-16  1069  {
1c710c89 Ulrich Drepper 2007-05-08  1070  	struct timespec tv[2];
^1da177e Linus Torvalds 2005-04-16  1071  
^1da177e Linus Torvalds 2005-04-16  1072  	if (tvs) {
1c710c89 Ulrich Drepper 2007-05-08  1073  		struct timeval ktvs[2];
^1da177e Linus Torvalds 2005-04-16 @1074  		if (get_tv32(&ktvs[0], &tvs[0]) ||
^1da177e Linus Torvalds 2005-04-16  1075  		    get_tv32(&ktvs[1], &tvs[1]))
^1da177e Linus Torvalds 2005-04-16  1076  			return -EFAULT;
1c710c89 Ulrich Drepper 2007-05-08  1077  
1c710c89 Ulrich Drepper 2007-05-08  1078  		if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
1c710c89 Ulrich Drepper 2007-05-08  1079  		    ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
1c710c89 Ulrich Drepper 2007-05-08  1080  			return -EINVAL;
1c710c89 Ulrich Drepper 2007-05-08  1081  
1c710c89 Ulrich Drepper 2007-05-08  1082  		tv[0].tv_sec = ktvs[0].tv_sec;

:::::: The code at line 1074 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 6cc0816..f3e557c 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1065,7 +1065,7 @@  SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
 }
 
 SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
-		struct timeval32 __user *, tvs)
+		const struct timeval32 __user *, tvs)
 {
 	struct timespec tv[2];
 
diff --git a/fs/compat.c b/fs/compat.c
index a71936a..5a6aa35 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -73,7 +73,7 @@  int compat_printk(const char *fmt, ...)
  * of sys_utimes.
  */
 COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename,
-		       struct compat_utimbuf __user *, t)
+		       const struct compat_utimbuf __user *, t)
 {
 	struct timespec tv[2];
 
@@ -87,7 +87,9 @@  COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename,
 	return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0);
 }
 
-COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags)
+COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd,
+		       const char __user *, filename,
+		       const struct compat_timespec __user *, t, int, flags)
 {
 	struct timespec tv[2];
 
@@ -102,7 +104,9 @@  COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filena
 	return do_utimes(dfd, filename, t ? tv : NULL, flags);
 }
 
-COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filename, struct compat_timeval __user *, t)
+COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd,
+		       const char __user *, filename,
+		       const struct compat_timeval __user *, t)
 {
 	struct timespec tv[2];
 
@@ -121,7 +125,8 @@  COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filena
 	return do_utimes(dfd, filename, t ? tv : NULL, 0);
 }
 
-COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timeval __user *, t)
+COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename,
+		       const struct compat_timeval __user *, t)
 {
 	return compat_sys_futimesat(AT_FDCWD, filename, t);
 }
diff --git a/fs/utimes.c b/fs/utimes.c
index 85c40f4..4954214 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -24,7 +24,8 @@ 
  * must be owner or have write permission.
  * Else, update from *times, must be owner or super user.
  */
-SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times)
+SYSCALL_DEFINE2(utime, const char __user *, filename,
+		const struct utimbuf __user *, times)
 {
 	struct timespec tv[2];
 
@@ -48,7 +49,7 @@  static bool nsec_valid(long nsec)
 	return nsec >= 0 && nsec <= 999999999;
 }
 
-static int utimes_common(struct path *path, struct timespec *times)
+static int utimes_common(struct path *path, const struct timespec *times)
 {
 	int error;
 	struct iattr newattrs;
@@ -133,8 +134,8 @@  out:
  * must be owner or have write permission.
  * Else, update from *times, must be owner or super user.
  */
-long do_utimes(int dfd, const char __user *filename, struct timespec *times,
-	       int flags)
+long do_utimes(int dfd, const char __user *filename,
+	       const struct timespec *times, int flags)
 {
 	int error = -EINVAL;
 
@@ -183,7 +184,7 @@  out:
 }
 
 SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
-		struct timespec __user *, utimes, int, flags)
+		const struct timespec __user *, utimes, int, flags)
 {
 	struct timespec tstimes[2];
 
@@ -201,7 +202,7 @@  SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
 }
 
 SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename,
-		struct timeval __user *, utimes)
+		const struct timeval __user *, utimes)
 {
 	struct timeval times[2];
 	struct timespec tstimes[2];
@@ -228,8 +229,8 @@  SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename,
 	return do_utimes(dfd, filename, utimes ? tstimes : NULL, 0);
 }
 
-SYSCALL_DEFINE2(utimes, char __user *, filename,
-		struct timeval __user *, utimes)
+SYSCALL_DEFINE2(utimes, const char __user *, filename,
+		const struct timeval __user *, utimes)
 {
 	return sys_futimesat(AT_FDCWD, filename, utimes);
 }
diff --git a/include/linux/compat.h b/include/linux/compat.h
index a76c917..d9bbfdb 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -453,10 +453,10 @@  asmlinkage long compat_sys_epoll_pwait(int epfd,
 			compat_size_t sigsetsize);
 
 asmlinkage long compat_sys_utime(const char __user *filename,
-				 struct compat_utimbuf __user *t);
+				 const struct compat_utimbuf __user *t);
 asmlinkage long compat_sys_utimensat(unsigned int dfd,
 				     const char __user *filename,
-				     struct compat_timespec __user *t,
+				     const struct compat_timespec __user *t,
 				     int flags);
 
 asmlinkage long compat_sys_time(compat_time_t __user *tloc);
@@ -477,9 +477,9 @@  asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
 				      int flags);
 asmlinkage long compat_sys_futimesat(unsigned int dfd,
 				     const char __user *filename,
-				     struct compat_timeval __user *t);
+				     const struct compat_timeval __user *t);
 asmlinkage long compat_sys_utimes(const char __user *filename,
-				  struct compat_timeval __user *t);
+				  const struct compat_timeval __user *t);
 asmlinkage long compat_sys_newstat(const char __user *filename,
 				   struct compat_stat __user *statbuf);
 asmlinkage long compat_sys_newlstat(const char __user *filename,
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 185815c..a82bb1f 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -550,10 +550,10 @@  asmlinkage long sys_getgid16(void);
 asmlinkage long sys_getegid16(void);
 #endif
 
-asmlinkage long sys_utime(char __user *filename,
-				struct utimbuf __user *times);
-asmlinkage long sys_utimes(char __user *filename,
-				struct timeval __user *utimes);
+asmlinkage long sys_utime(const char __user *filename,
+			  const struct utimbuf __user *times);
+asmlinkage long sys_utimes(const char __user *filename,
+			   const struct timeval __user *utimes);
 asmlinkage long sys_lseek(unsigned int fd, off_t offset,
 			  unsigned int whence);
 asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
@@ -765,7 +765,7 @@  asmlinkage long sys_renameat2(int olddfd, const char __user *oldname,
 			      int newdfd, const char __user *newname,
 			      unsigned int flags);
 asmlinkage long sys_futimesat(int dfd, const char __user *filename,
-			      struct timeval __user *utimes);
+			      const struct timeval __user *utimes);
 asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
 asmlinkage long sys_fchmodat(int dfd, const char __user * filename,
 			     umode_t mode);
@@ -778,7 +778,7 @@  asmlinkage long sys_newfstatat(int dfd, const char __user *filename,
 asmlinkage long sys_readlinkat(int dfd, const char __user *path, char __user *buf,
 			       int bufsiz);
 asmlinkage long sys_utimensat(int dfd, const char __user *filename,
-				struct timespec __user *utimes, int flags);
+			      const struct timespec __user *utimes, int flags);
 asmlinkage long sys_unshare(unsigned long unshare_flags);
 
 asmlinkage long sys_splice(int fd_in, loff_t __user *off_in,
diff --git a/include/linux/time.h b/include/linux/time.h
index 297f09f..20b28fb 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -174,7 +174,8 @@  extern int do_getitimer(int which, struct itimerval *value);
 
 extern unsigned int alarm_setitimer(unsigned int seconds);
 
-extern long do_utimes(int dfd, const char __user *filename, struct timespec *times, int flags);
+extern long do_utimes(int dfd, const char __user *filename,
+		      const struct timespec *times, int flags);
 
 struct tms;
 extern void do_sys_times(struct tms *);