2021-07-23 20:06:15

by Fabio M. De Francesco

[permalink] [raw]
Subject: [PATCH] staging: android: Remove set but unused variable in ashmem.c

Remove variable 'inode' tnat is set but unused. Issue detected
by building with warning option -Wunused-but-set-variable.

Signed-off-by: Fabio M. De Francesco <[email protected]>
---
drivers/staging/android/ashmem.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index ddbde3f8430e..606e988d3f63 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -406,7 +406,6 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
if (!asma->file) {
char *name = ASHMEM_NAME_DEF;
struct file *vmfile;
- struct inode *inode;

if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
name = asma->name;
@@ -418,7 +417,6 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
goto out;
}
vmfile->f_mode |= FMODE_LSEEK;
- inode = file_inode(vmfile);
lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
asma->file = vmfile;
/*
--
2.32.0


2021-07-23 20:16:12

by Suren Baghdasaryan

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

On Fri, Jul 23, 2021 at 1:05 PM Fabio M. De Francesco
<[email protected]> wrote:
>
> Remove variable 'inode' tnat is set but unused. Issue detected
> by building with warning option -Wunused-but-set-variable.
>
> Signed-off-by: Fabio M. De Francesco <[email protected]>
> ---
> drivers/staging/android/ashmem.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> index ddbde3f8430e..606e988d3f63 100644
> --- a/drivers/staging/android/ashmem.c
> +++ b/drivers/staging/android/ashmem.c
> @@ -406,7 +406,6 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
> if (!asma->file) {
> char *name = ASHMEM_NAME_DEF;
> struct file *vmfile;
> - struct inode *inode;
>
> if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
> name = asma->name;
> @@ -418,7 +417,6 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
> goto out;
> }
> vmfile->f_mode |= FMODE_LSEEK;
> - 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 guessing you are building with CONFIG_LOCKDEP=n.
Have you tried adding __maybe_unused in inode variable definition to
get rid of the warning?


> asma->file = vmfile;
> /*
> --
> 2.32.0
>

2021-07-24 02:56:30

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

Hi "Fabio,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]

url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-android-Remove-set-but-unused-variable-in-ashmem-c/20210724-040651
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git f133717efc6f28052667daf682e99ffd4b3d7588
config: arm64-randconfig-r015-20210723 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 10.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/7e8f2aa391f91bb404e9c1b508cf3d13b0cfde94
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-android-Remove-set-but-unused-variable-in-ashmem-c/20210724-040651
git checkout 7e8f2aa391f91bb404e9c1b508cf3d13b0cfde94
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/staging/android/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

In file included from include/linux/spinlock.h:59,
from include/linux/wait.h:9,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from drivers/staging/android/ashmem.c:16:
drivers/staging/android/ashmem.c: In function 'ashmem_mmap':
>> drivers/staging/android/ashmem.c:420:22: error: 'inode' undeclared (first use in this function)
420 | lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
| ^~~~~
include/linux/lockdep.h:218:27: note: in definition of macro 'lockdep_set_class'
218 | lockdep_init_map_waits(&(lock)->dep_map, #key, key, 0, \
| ^~~~
drivers/staging/android/ashmem.c:420:22: note: each undeclared identifier is reported only once for each function it appears in
420 | lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
| ^~~~~
include/linux/lockdep.h:218:27: note: in definition of macro 'lockdep_set_class'
218 | lockdep_init_map_waits(&(lock)->dep_map, #key, key, 0, \
| ^~~~


vim +/inode +420 drivers/staging/android/ashmem.c

6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 377
11980c2ac4ccfa Robert Love 2011-12-20 378 static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
11980c2ac4ccfa Robert Love 2011-12-20 379 {
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 380 static struct file_operations vmfile_fops;
11980c2ac4ccfa Robert Love 2011-12-20 381 struct ashmem_area *asma = file->private_data;
11980c2ac4ccfa Robert Love 2011-12-20 382 int ret = 0;
11980c2ac4ccfa Robert Love 2011-12-20 383
11980c2ac4ccfa Robert Love 2011-12-20 384 mutex_lock(&ashmem_mutex);
11980c2ac4ccfa Robert Love 2011-12-20 385
11980c2ac4ccfa Robert Love 2011-12-20 386 /* user needs to SET_SIZE before mapping */
59848d6aded59a Alistair Strachan 2018-06-19 387 if (!asma->size) {
11980c2ac4ccfa Robert Love 2011-12-20 388 ret = -EINVAL;
11980c2ac4ccfa Robert Love 2011-12-20 389 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 390 }
11980c2ac4ccfa Robert Love 2011-12-20 391
8632c614565d0c Alistair Strachan 2018-06-19 392 /* requested mapping size larger than object size */
8632c614565d0c Alistair Strachan 2018-06-19 393 if (vma->vm_end - vma->vm_start > PAGE_ALIGN(asma->size)) {
11980c2ac4ccfa Robert Love 2011-12-20 394 ret = -EINVAL;
11980c2ac4ccfa Robert Love 2011-12-20 395 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 396 }
11980c2ac4ccfa Robert Love 2011-12-20 397
11980c2ac4ccfa Robert Love 2011-12-20 398 /* requested protection bits must match our allowed protection mask */
59848d6aded59a Alistair Strachan 2018-06-19 399 if ((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) &
59848d6aded59a Alistair Strachan 2018-06-19 400 calc_vm_prot_bits(PROT_MASK, 0)) {
11980c2ac4ccfa Robert Love 2011-12-20 401 ret = -EPERM;
11980c2ac4ccfa Robert Love 2011-12-20 402 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 403 }
56f76fc68492af Arve Hj?nnev?g 2011-12-20 404 vma->vm_flags &= ~calc_vm_may_flags(~asma->prot_mask);
11980c2ac4ccfa Robert Love 2011-12-20 405
11980c2ac4ccfa Robert Love 2011-12-20 406 if (!asma->file) {
11980c2ac4ccfa Robert Love 2011-12-20 407 char *name = ASHMEM_NAME_DEF;
11980c2ac4ccfa Robert Love 2011-12-20 408 struct file *vmfile;
11980c2ac4ccfa Robert Love 2011-12-20 409
11980c2ac4ccfa Robert Love 2011-12-20 410 if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
11980c2ac4ccfa Robert Love 2011-12-20 411 name = asma->name;
11980c2ac4ccfa Robert Love 2011-12-20 412
11980c2ac4ccfa Robert Love 2011-12-20 413 /* ... and allocate the backing shmem file */
11980c2ac4ccfa Robert Love 2011-12-20 414 vmfile = shmem_file_setup(name, asma->size, vma->vm_flags);
7f44cb0ba88b40 Viresh Kumar 2015-07-31 415 if (IS_ERR(vmfile)) {
11980c2ac4ccfa Robert Love 2011-12-20 416 ret = PTR_ERR(vmfile);
11980c2ac4ccfa Robert Love 2011-12-20 417 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 418 }
97fbfef6bd5978 Shuxiao Zhang 2017-04-06 419 vmfile->f_mode |= FMODE_LSEEK;
3e338d3c95c735 Suren Baghdasaryan 2020-07-30 @420 lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
11980c2ac4ccfa Robert Love 2011-12-20 421 asma->file = vmfile;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 422 /*
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 423 * override mmap operation of the vmfile so that it can't be
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 424 * remapped which would lead to creation of a new vma with no
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 425 * asma permission checks. Have to override get_unmapped_area
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 426 * as well to prevent VM_BUG_ON check for f_ops modification.
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 427 */
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 428 if (!vmfile_fops.mmap) {
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 429 vmfile_fops = *vmfile->f_op;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 430 vmfile_fops.mmap = ashmem_vmfile_mmap;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 431 vmfile_fops.get_unmapped_area =
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 432 ashmem_vmfile_get_unmapped_area;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 433 }
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 434 vmfile->f_op = &vmfile_fops;
11980c2ac4ccfa Robert Love 2011-12-20 435 }
11980c2ac4ccfa Robert Love 2011-12-20 436 get_file(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 437
11980c2ac4ccfa Robert Love 2011-12-20 438 /*
11980c2ac4ccfa Robert Love 2011-12-20 439 * XXX - Reworked to use shmem_zero_setup() instead of
11980c2ac4ccfa Robert Love 2011-12-20 440 * shmem_set_file while we're in staging. -jstultz
11980c2ac4ccfa Robert Love 2011-12-20 441 */
11980c2ac4ccfa Robert Love 2011-12-20 442 if (vma->vm_flags & VM_SHARED) {
11980c2ac4ccfa Robert Love 2011-12-20 443 ret = shmem_zero_setup(vma);
11980c2ac4ccfa Robert Love 2011-12-20 444 if (ret) {
11980c2ac4ccfa Robert Love 2011-12-20 445 fput(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 446 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 447 }
44960f2a7b63e2 John Stultz 2018-07-31 448 } else {
44960f2a7b63e2 John Stultz 2018-07-31 449 vma_set_anonymous(vma);
11980c2ac4ccfa Robert Love 2011-12-20 450 }
11980c2ac4ccfa Robert Love 2011-12-20 451
295992fb815e79 Christian K?nig 2020-09-14 452 vma_set_file(vma, asma->file);
295992fb815e79 Christian K?nig 2020-09-14 453 /* XXX: merge this with the get_file() above if possible */
295992fb815e79 Christian K?nig 2020-09-14 454 fput(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 455
11980c2ac4ccfa Robert Love 2011-12-20 456 out:
11980c2ac4ccfa Robert Love 2011-12-20 457 mutex_unlock(&ashmem_mutex);
11980c2ac4ccfa Robert Love 2011-12-20 458 return ret;
11980c2ac4ccfa Robert Love 2011-12-20 459 }
11980c2ac4ccfa Robert Love 2011-12-20 460

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (9.03 kB)
.config.gz (32.65 kB)
Download all attachments

2021-07-24 03:16:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

Hi "Fabio,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]

url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-android-Remove-set-but-unused-variable-in-ashmem-c/20210724-040651
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git f133717efc6f28052667daf682e99ffd4b3d7588
config: x86_64-randconfig-a002-20210723 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9625ca5b602616b2f5584e8a49ba93c52c141e40)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/7e8f2aa391f91bb404e9c1b508cf3d13b0cfde94
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-android-Remove-set-but-unused-variable-in-ashmem-c/20210724-040651
git checkout 7e8f2aa391f91bb404e9c1b508cf3d13b0cfde94
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/staging/android/ashmem.c:420:22: error: use of undeclared identifier 'inode'
lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
^
>> drivers/staging/android/ashmem.c:420:22: error: use of undeclared identifier 'inode'
>> drivers/staging/android/ashmem.c:420:22: error: use of undeclared identifier 'inode'
3 errors generated.


vim +/inode +420 drivers/staging/android/ashmem.c

6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 377
11980c2ac4ccfa Robert Love 2011-12-20 378 static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
11980c2ac4ccfa Robert Love 2011-12-20 379 {
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 380 static struct file_operations vmfile_fops;
11980c2ac4ccfa Robert Love 2011-12-20 381 struct ashmem_area *asma = file->private_data;
11980c2ac4ccfa Robert Love 2011-12-20 382 int ret = 0;
11980c2ac4ccfa Robert Love 2011-12-20 383
11980c2ac4ccfa Robert Love 2011-12-20 384 mutex_lock(&ashmem_mutex);
11980c2ac4ccfa Robert Love 2011-12-20 385
11980c2ac4ccfa Robert Love 2011-12-20 386 /* user needs to SET_SIZE before mapping */
59848d6aded59a Alistair Strachan 2018-06-19 387 if (!asma->size) {
11980c2ac4ccfa Robert Love 2011-12-20 388 ret = -EINVAL;
11980c2ac4ccfa Robert Love 2011-12-20 389 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 390 }
11980c2ac4ccfa Robert Love 2011-12-20 391
8632c614565d0c Alistair Strachan 2018-06-19 392 /* requested mapping size larger than object size */
8632c614565d0c Alistair Strachan 2018-06-19 393 if (vma->vm_end - vma->vm_start > PAGE_ALIGN(asma->size)) {
11980c2ac4ccfa Robert Love 2011-12-20 394 ret = -EINVAL;
11980c2ac4ccfa Robert Love 2011-12-20 395 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 396 }
11980c2ac4ccfa Robert Love 2011-12-20 397
11980c2ac4ccfa Robert Love 2011-12-20 398 /* requested protection bits must match our allowed protection mask */
59848d6aded59a Alistair Strachan 2018-06-19 399 if ((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) &
59848d6aded59a Alistair Strachan 2018-06-19 400 calc_vm_prot_bits(PROT_MASK, 0)) {
11980c2ac4ccfa Robert Love 2011-12-20 401 ret = -EPERM;
11980c2ac4ccfa Robert Love 2011-12-20 402 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 403 }
56f76fc68492af Arve Hj?nnev?g 2011-12-20 404 vma->vm_flags &= ~calc_vm_may_flags(~asma->prot_mask);
11980c2ac4ccfa Robert Love 2011-12-20 405
11980c2ac4ccfa Robert Love 2011-12-20 406 if (!asma->file) {
11980c2ac4ccfa Robert Love 2011-12-20 407 char *name = ASHMEM_NAME_DEF;
11980c2ac4ccfa Robert Love 2011-12-20 408 struct file *vmfile;
11980c2ac4ccfa Robert Love 2011-12-20 409
11980c2ac4ccfa Robert Love 2011-12-20 410 if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
11980c2ac4ccfa Robert Love 2011-12-20 411 name = asma->name;
11980c2ac4ccfa Robert Love 2011-12-20 412
11980c2ac4ccfa Robert Love 2011-12-20 413 /* ... and allocate the backing shmem file */
11980c2ac4ccfa Robert Love 2011-12-20 414 vmfile = shmem_file_setup(name, asma->size, vma->vm_flags);
7f44cb0ba88b40 Viresh Kumar 2015-07-31 415 if (IS_ERR(vmfile)) {
11980c2ac4ccfa Robert Love 2011-12-20 416 ret = PTR_ERR(vmfile);
11980c2ac4ccfa Robert Love 2011-12-20 417 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 418 }
97fbfef6bd5978 Shuxiao Zhang 2017-04-06 419 vmfile->f_mode |= FMODE_LSEEK;
3e338d3c95c735 Suren Baghdasaryan 2020-07-30 @420 lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class);
11980c2ac4ccfa Robert Love 2011-12-20 421 asma->file = vmfile;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 422 /*
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 423 * override mmap operation of the vmfile so that it can't be
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 424 * remapped which would lead to creation of a new vma with no
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 425 * asma permission checks. Have to override get_unmapped_area
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 426 * as well to prevent VM_BUG_ON check for f_ops modification.
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 427 */
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 428 if (!vmfile_fops.mmap) {
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 429 vmfile_fops = *vmfile->f_op;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 430 vmfile_fops.mmap = ashmem_vmfile_mmap;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 431 vmfile_fops.get_unmapped_area =
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 432 ashmem_vmfile_get_unmapped_area;
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 433 }
6d67b0290b4b84 Suren Baghdasaryan 2020-01-27 434 vmfile->f_op = &vmfile_fops;
11980c2ac4ccfa Robert Love 2011-12-20 435 }
11980c2ac4ccfa Robert Love 2011-12-20 436 get_file(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 437
11980c2ac4ccfa Robert Love 2011-12-20 438 /*
11980c2ac4ccfa Robert Love 2011-12-20 439 * XXX - Reworked to use shmem_zero_setup() instead of
11980c2ac4ccfa Robert Love 2011-12-20 440 * shmem_set_file while we're in staging. -jstultz
11980c2ac4ccfa Robert Love 2011-12-20 441 */
11980c2ac4ccfa Robert Love 2011-12-20 442 if (vma->vm_flags & VM_SHARED) {
11980c2ac4ccfa Robert Love 2011-12-20 443 ret = shmem_zero_setup(vma);
11980c2ac4ccfa Robert Love 2011-12-20 444 if (ret) {
11980c2ac4ccfa Robert Love 2011-12-20 445 fput(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 446 goto out;
11980c2ac4ccfa Robert Love 2011-12-20 447 }
44960f2a7b63e2 John Stultz 2018-07-31 448 } else {
44960f2a7b63e2 John Stultz 2018-07-31 449 vma_set_anonymous(vma);
11980c2ac4ccfa Robert Love 2011-12-20 450 }
11980c2ac4ccfa Robert Love 2011-12-20 451
295992fb815e79 Christian K?nig 2020-09-14 452 vma_set_file(vma, asma->file);
295992fb815e79 Christian K?nig 2020-09-14 453 /* XXX: merge this with the get_file() above if possible */
295992fb815e79 Christian K?nig 2020-09-14 454 fput(asma->file);
11980c2ac4ccfa Robert Love 2011-12-20 455
11980c2ac4ccfa Robert Love 2011-12-20 456 out:
11980c2ac4ccfa Robert Love 2011-12-20 457 mutex_unlock(&ashmem_mutex);
11980c2ac4ccfa Robert Love 2011-12-20 458 return ret;
11980c2ac4ccfa Robert Love 2011-12-20 459 }
11980c2ac4ccfa Robert Love 2011-12-20 460

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (8.42 kB)
.config.gz (39.85 kB)
Download all attachments

2021-07-24 07:52:06

by Fabio M. De Francesco

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

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
>
> <[email protected]> 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




2021-07-26 13:46:34

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

On Sat, Jul 24, 2021 at 09:49:35AM +0200, Fabio M. De Francesco wrote:
> On Friday, July 23, 2021 10:14:46 PM CEST Suren Baghdasaryan wrote:
> > 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.

Another trick which would have helped is to try find out which patch
forgot to remove the "inode" variale, because that developer would have
seen the warning as well.


>
> > 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.

Use make nconfig and then use f8 to search for CONFIG_LOCKDEP.

regards,
dan carpenter

2021-07-28 12:05:13

by Fabio M. De Francesco

[permalink] [raw]
Subject: Re: [PATCH] staging: android: Remove set but unused variable in ashmem.c

Hello Dan,

On Monday, July 26, 2021 3:44:54 PM CEST Dan Carpenter wrote:
> On Sat, Jul 24, 2021 at 09:49:35AM +0200, Fabio M. De Francesco wrote:
> >
> > [...]
> >
> Another trick which would have helped is to try find out which patch
> forgot to remove the "inode" variable, because that developer would have
> seen the warning as well.
>
> > > 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.
>
> Use make nconfig and then use f8 to search for CONFIG_LOCKDEP.
>
> regards,
> dan carpenter

Thanks a lot. As always, you've been very helpful. I appreciate your
willingness to help and, more generally, your attitude towards people with
less experience than yours.

By using F8, I found that CONFIG_LOCKDEP is selected by CONFIG_LOCK_STAT (in
logical AND with other options) but, in my .config, the latter was set to 'n'.
After setting this other option to 'y', CONFIG_LOCKDEP magically :) appeared
in .config and it was automatically set to 'y'.

I see that the same kind of search can also be done by using the slash if one
uses "make menuconfig".

Regards,

Fabio