Content-Type: multipart/mixed; boundary="===============2232526137458471665==" MIME-Version: 1.0 From: Kuniyuki Iwashima To: kbuild-all@lists.01.org Subject: Re: [PATCH] fs/lock: Don't allocate file_lock in flock_make_lock(). Date: Sat, 16 Jul 2022 13:57:21 -0700 Message-ID: <20220716205721.15412-1-kuniyu@amazon.com> In-Reply-To: <202207170400.ddCuQ7sy-lkp@intel.com> List-Id: --===============2232526137458471665== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: kernel test robot Date: Sun, 17 Jul 2022 04:46:27 +0800 > Hi Kuniyuki, > = > Thank you for the patch! Perhaps something to improve: > = > [auto build test WARNING on linus/master] > [also build test WARNING on v5.19-rc6 next-20220715] > [cannot apply to jlayton/linux-next cel-2.6/for-next] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > = > url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/= fs-lock-Don-t-allocate-file_lock-in-flock_make_lock/20220716-225519 > base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.gi= t 9b59ec8d50a1f28747ceff9a4f39af5deba9540e > config: mips-randconfig-r003-20220715 (https://download.01.org/0day-ci/ar= chive/20220717/202207170400.ddCuQ7sy-lkp(a)intel.com/config) > compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 0702= 2e6cf9b5b3baa642be53d0b3c3f1c403dbfd) > reproduce (this is a W=3D1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbi= n/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # install mips cross compiling tool for clang build > # apt-get install binutils-mipsel-linux-gnu > # https://github.com/intel-lab-lkp/linux/commit/7f68b5b24c3d8d371= fb96ebe278dabb8c08bbf51 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review Kuniyuki-Iwashima/fs-lock-Don-t-= allocate-file_lock-in-flock_make_lock/20220716-225519 > git checkout 7f68b5b24c3d8d371fb96ebe278dabb8c08bbf51 > # save the config file > mkdir build_dir && cp config build_dir/.config > COMPILER_INSTALL_PATH=3D$HOME/0day COMPILER=3Dclang make.cross W= =3D1 O=3Dbuild_dir ARCH=3Dmips SHELL=3D/bin/bash > = > If you fix the issue, kindly add following tag where applicable > Reported-by: kernel test robot > = > All warnings (new ones prefixed by >>): > = > >> fs/locks.c:2103:6: warning: variable 'error' is used uninitialized whe= never 'if' condition is true [-Wsometimes-uninitialized] > if (!unlock && !(f.file->f_mode & (FMODE_READ|FMODE_WRITE))) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Oops, I'll fix this in v2. Thanks! > fs/locks.c:2139:9: note: uninitialized use occurs here > return error; > ^~~~~ > fs/locks.c:2103:2: note: remove the 'if' if its condition is always fa= lse > if (!unlock && !(f.file->f_mode & (FMODE_READ|FMODE_WRITE))) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > fs/locks.c:2089:11: note: initialize the variable 'error' to silence t= his warning > int error; > ^ > =3D 0 > 1 warning generated. > = > = > vim +2103 fs/locks.c > = > e55c34a66f87e7 Benjamin Coddington 2015-10-22 2068 = > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2069 /** > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2070 * sys_flock: - fl= ock() system call. > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2071 * @fd: the file d= escriptor to lock. > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2072 * @cmd: the type = of lock to apply. > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2073 * > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2074 * Apply a %FL_FLO= CK style lock to an open file descriptor. > 80b79dd0e2f29f Mauro Carvalho Chehab 2017-05-27 2075 * The @cmd can be= one of: > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2076 * > 80b79dd0e2f29f Mauro Carvalho Chehab 2017-05-27 2077 * - %LOCK_SH -- a= shared lock. > 80b79dd0e2f29f Mauro Carvalho Chehab 2017-05-27 2078 * - %LOCK_EX -- a= n exclusive lock. > 80b79dd0e2f29f Mauro Carvalho Chehab 2017-05-27 2079 * - %LOCK_UN -- r= emove an existing lock. > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2080 * - %LOCK_MAND --= a 'mandatory' flock. (DEPRECATED) > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2081 * > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2082 * %LOCK_MAND supp= ort has been removed from the kernel. > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2083 */ > 002c8976ee5377 Heiko Carstens 2009-01-14 2084 SYSCALL_DEFINE2(fl= ock, unsigned int, fd, unsigned int, cmd) > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2085 { > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2086 int can_sleep, un= lock, type; > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2087 struct file_lock = fl; > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2088 struct fd f; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2089 int error; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2090 = > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2091 type =3D flock_tr= anslate_cmd(cmd); > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2092 if (type < 0) > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2093 return type; > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2094 = > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2095 f =3D fdget(fd); > 2903ff019b346a Al Viro 2012-08-28 2096 if (!f.file) > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2097 return -EBADF; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2098 = > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2099 can_sleep =3D !(c= md & LOCK_NB); > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2100 cmd &=3D ~LOCK_NB; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2101 unlock =3D (cmd = =3D=3D LOCK_UN); > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2102 = > 90f7d7a0d0d686 Jeff Layton 2021-09-10 @2103 if (!unlock && !(= f.file->f_mode & (FMODE_READ|FMODE_WRITE))) > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2104 goto out_putf; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2105 = > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2106 /* > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2107 * LOCK_MAND lock= s were broken for a long time in that they never > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2108 * conflicted wit= h one another and didn't prevent any sort of open, > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2109 * read or write = activity. > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2110 * > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2111 * Just ignore th= ese requests now, to preserve legacy behavior, but > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2112 * throw a warnin= g to let people know that they don't actually work. > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2113 */ > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2114 if (cmd & LOCK_MA= ND) { > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2115 pr_warn_once("At= tempt to set a LOCK_MAND lock via flock(2). This support has been removed a= nd the request ignored.\n"); > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2116 error =3D 0; > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2117 goto out_putf; > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2118 } > 90f7d7a0d0d686 Jeff Layton 2021-09-10 2119 = > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2120 flock_make_lock(f= .file, &fl, type); > 6e129d00689c4d Jeff Layton 2014-09-04 2121 = > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2122 if (can_sleep) > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2123 fl.fl_flags |=3D= FL_SLEEP; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2124 = > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2125 error =3D securit= y_file_lock(f.file, fl.fl_type); > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2126 if (error) > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2127 goto out_putf; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2128 = > de2a4a501e716b Miklos Szeredi 2018-07-18 2129 if (f.file->f_op-= >flock) > 2903ff019b346a Al Viro 2012-08-28 2130 error =3D f.file= ->f_op->flock(f.file, > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2131 can_sleep= ? F_SETLKW : F_SETLK, > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2132 &fl); > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2133 else > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2134 error =3D locks_= lock_file_wait(f.file, &fl); > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2135 = > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2136 out_putf: > 2903ff019b346a Al Viro 2012-08-28 2137 fdput(f); > 7f68b5b24c3d8d Kuniyuki Iwashima 2022-07-15 2138 = > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2139 return error; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2140 } > ^1da177e4c3f41 Linus Torvalds 2005-04-16 2141 = > = > -- = > 0-DAY CI Kernel Test Service > https://01.org/lkp --===============2232526137458471665==--