Re: [akpm-mm:mm-unstable 26/98] fs/libfs.c:1231:47: warning: Local variable 'anon_aops' shadows outer variable [shadowVariable]
From: Andrew Morton
Date: Wed Aug 17 2022 - 13:10:54 EST
On Mon, 15 Aug 2022 23:36:43 +0800 kernel test robot <lkp@xxxxxxxxx> wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> head: d2af7b221349ff6241e25fa8c67bcfae2b360700
> commit: e4ab315810850b93cac381d6f4efd532f45a790e [26/98] procfs: add 'path' to /proc/<pid>/fdinfo/
> compiler: or1k-linux-gcc (GCC) 12.1.0
> reproduce (cppcheck warning):
> # apt-get install cppcheck
> git checkout e4ab315810850b93cac381d6f4efd532f45a790e
> cppcheck --quiet --enable=style,performance,portability --template=gcc FILE
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
>
> cppcheck warnings: (new ones prefixed by >>)
> >> init/main.c:333:18: warning: Pointer addition with NULL pointer. [nullPointerArithmetic]
> char *end = buf + size;
> ^
> init/main.c:376:28: note: Calling function 'xbc_snprint_cmdline', 1st argument 'NULL' value is 0
> len = xbc_snprint_cmdline(NULL, 0, root);
> ^
> init/main.c:333:18: note: Null pointer addition
> char *end = buf + size;
That's a pretty useless warning.
> >> fs/libfs.c:1231:47: warning: Local variable 'anon_aops' shadows outer variable [shadowVariable]
> static const struct address_space_operations anon_aops = {
> ^
> fs/libfs.c:1220:46: note: Shadowed declaration
> static const struct address_space_operations anon_aops = {
> ^
> fs/libfs.c:1231:47: note: Shadow variable
> static const struct address_space_operations anon_aops = {
That's worth addressing.
--- a/fs/libfs.c~procfs-add-path-to-proc-pid-fdinfo-fix
+++ a/fs/libfs.c
@@ -1228,7 +1228,7 @@ bool is_anon_inode(struct inode *inode)
struct inode *alloc_anon_inode(struct super_block *s)
{
- static const struct address_space_operations anon_aops = {
+ static const struct address_space_operations aops = {
.dirty_folio = noop_dirty_folio,
};
struct inode *inode = new_inode_pseudo(s);
@@ -1237,7 +1237,7 @@ struct inode *alloc_anon_inode(struct su
return ERR_PTR(-ENOMEM);
inode->i_ino = get_next_ino();
- inode->i_mapping->a_ops = &anon_aops;
+ inode->i_mapping->a_ops = &aops;
/*
* Mark the inode dirty from the very beginning,
_