From: Christoph Hellwig <hch@lst.de>
To: kbuild-all@lists.01.org
Subject: Re: fs/init.c:72:8: warning: Variable 'error' is reassigned a value before the old one has been used.
Date: Sat, 08 Aug 2020 07:40:07 +0200 [thread overview]
Message-ID: <20200808054006.GA16706@lst.de> (raw)
In-Reply-To: <202008081143.D8Y8xO2X%lkp@intel.com>
[-- Attachment #1: Type: text/plain, Size: 2170 bytes --]
On Sat, Aug 08, 2020 at 11:35:45AM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 30185b69a2d533c4ba6ca926b8390ce7de495e29
> commit: 4b7ca5014cbef51cdb99fd644eae4f3773747a05 init: add an init_chroot helper
> date: 8 days ago
> compiler: hppa-linux-gcc (GCC) 9.3.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
>
> cppcheck warnings: (new ones prefixed by >>)
>
> >> fs/init.c:72:8: warning: Variable 'error' is reassigned a value before the old one has been used. [redundantAssignment]
> error = security_path_chroot(&path);
> ^
> fs/init.c:69:8: note: Variable 'error' is reassigned a value before the old one has been used.
> error = -EPERM;
> ^
> fs/init.c:72:8: note: Variable 'error' is reassigned a value before the old one has been used.
> error = security_path_chroot(&path);
I really don't understand the warning. We assign a value to error, if
there is an error we jump the out labe and return it, or else continue.
That is a pretty common pattern in the kernel. What do I miss?
>
> vim +/error +72 fs/init.c
>
> 57
> 58 int __init init_chroot(const char *filename)
> 59 {
> 60 struct path path;
> 61 int error;
> 62
> 63 error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
> 64 if (error)
> 65 return error;
> 66 error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
> 67 if (error)
> 68 goto dput_and_out;
> 69 error = -EPERM;
> 70 if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
> 71 goto dput_and_out;
> > 72 error = security_path_chroot(&path);
> 73 if (error)
> 74 goto dput_and_out;
> 75 set_fs_root(current->fs, &path);
> 76 dput_and_out:
> 77 path_put(&path);
> 78 return error;
> 79 }
> 80
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
---end quoted text---
WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: kernel test robot <lkp@intel.com>
Cc: Christoph Hellwig <hch@lst.de>,
kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
viro@zeniv.linux.org.uk
Subject: Re: fs/init.c:72:8: warning: Variable 'error' is reassigned a value before the old one has been used.
Date: Sat, 8 Aug 2020 07:40:07 +0200 [thread overview]
Message-ID: <20200808054006.GA16706@lst.de> (raw)
In-Reply-To: <202008081143.D8Y8xO2X%lkp@intel.com>
On Sat, Aug 08, 2020 at 11:35:45AM +0800, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 30185b69a2d533c4ba6ca926b8390ce7de495e29
> commit: 4b7ca5014cbef51cdb99fd644eae4f3773747a05 init: add an init_chroot helper
> date: 8 days ago
> compiler: hppa-linux-gcc (GCC) 9.3.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
>
> cppcheck warnings: (new ones prefixed by >>)
>
> >> fs/init.c:72:8: warning: Variable 'error' is reassigned a value before the old one has been used. [redundantAssignment]
> error = security_path_chroot(&path);
> ^
> fs/init.c:69:8: note: Variable 'error' is reassigned a value before the old one has been used.
> error = -EPERM;
> ^
> fs/init.c:72:8: note: Variable 'error' is reassigned a value before the old one has been used.
> error = security_path_chroot(&path);
I really don't understand the warning. We assign a value to error, if
there is an error we jump the out labe and return it, or else continue.
That is a pretty common pattern in the kernel. What do I miss?
>
> vim +/error +72 fs/init.c
>
> 57
> 58 int __init init_chroot(const char *filename)
> 59 {
> 60 struct path path;
> 61 int error;
> 62
> 63 error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
> 64 if (error)
> 65 return error;
> 66 error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
> 67 if (error)
> 68 goto dput_and_out;
> 69 error = -EPERM;
> 70 if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
> 71 goto dput_and_out;
> > 72 error = security_path_chroot(&path);
> 73 if (error)
> 74 goto dput_and_out;
> 75 set_fs_root(current->fs, &path);
> 76 dput_and_out:
> 77 path_put(&path);
> 78 return error;
> 79 }
> 80
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
---end quoted text---
next prev parent reply other threads:[~2020-08-08 5:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-08 3:35 fs/init.c:72:8: warning: Variable 'error' is reassigned a value before the old one has been used kernel test robot
2020-08-08 3:35 ` kernel test robot
2020-08-08 5:40 ` Christoph Hellwig [this message]
2020-08-08 5:40 ` Christoph Hellwig
2020-08-10 9:28 ` Xia, Hui
2020-08-10 9:28 ` [kbuild-all] " Xia, Hui
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=20200808054006.GA16706@lst.de \
--to=hch@lst.de \
--cc=kbuild-all@lists.01.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.