Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c
From: Fabio M. De Francesco
Date: Sat Jul 24 2021 - 03:49:42 EST
On Friday, July 23, 2021 10:14:46 PM CEST Suren Baghdasaryan wrote:
> On Fri, Jul 23, 2021 at 1:05 PM Fabio M. De Francesco
>
> <fmdefrancesco@xxxxxxxxx> wrote:
> > Remove variable 'inode' tnat is set but unused. Issue detected
> > by building with warning option -Wunused-but-set-variable.
> >
> > [...]
> >
> > - inode = file_inode(vmfile);
> >
> > lockdep_set_class(&inode->i_rwsem,
&backing_shmem_inode_class);
>
> How about its usage in the above lockdep_set_class(&inode->i_rwsem,
> ...) call?
I'm sorry. I didn't notice that 'inode' is used soon after assignment, just in
the line that follows it. I was also too confident that rebuilding the driver
would have triggered an error if it is used somewhere else. I was obviously
wrong.
Furthermore, I usually automatically search with grep or other tools for other
occurrences of a symbol in the function and the file, but this time I must
have forgotten to do that.
> I'm guessing you are building with CONFIG_LOCKDEP=n.
Actually my .config sets CONFIG_LOCKDEP_SUPPORT=y. Did you refer to this?
There is no CONFIG_LOCKDEP in the file.
I've just run "make clean && make C=2 -j8 drivers/staging/android/ W=1" one
more time and it still builds. How is it possible that the code builds
correctly with my configuration?
This is the output (the last two lines) of 'make':
CC drivers/staging/android/ashmem.o
AR drivers/staging/android/built-in.
There are no errors or warnings, even with that "lockdep_set_class(&inode-
>i_rwsem, &backing_shmem_inode_class);" left as-is after 'inode' removal.
I really can't understand what I'm missing.
> Have you tried adding __maybe_unused in inode variable definition to
> get rid of the warning?
>
Actually, I didn't know that directive that you mention. I'll read the
documentation and, if and where suited, I'll use it.
Thanks,
Fabio
>
> > [...]
> > --
> > 2.32.0