2022-08-15 08:42:56

by Dan Carpenter

[permalink] [raw]
Subject: fs/afs/server.c:406 afs_put_server() warn: variable dereferenced before check 'server' (see line 402)

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
commit: 2757a4dc184997c66ef1de32636f73b9f21aac14 afs: Fix access after dec in put functions
config: parisc-randconfig-m031-20220807 (https://download.01.org/0day-ci/archive/20220815/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
fs/afs/server.c:406 afs_put_server() warn: variable dereferenced before check 'server' (see line 402)

vim +/server +406 fs/afs/server.c

452181936931f0 David Howells 2019-06-20 399 void afs_put_server(struct afs_net *net, struct afs_server *server,
452181936931f0 David Howells 2019-06-20 400 enum afs_server_trace reason)
^1da177e4c3f41 Linus Torvalds 2005-04-16 401 {
2757a4dc184997 David Howells 2022-07-06 @402 unsigned int a, debug_id = server->debug_id;
^^^^^^^^^^^^^^^^
Dereferenced

c56f9ec8b20f93 David Howells 2022-07-06 403 bool zero;
c56f9ec8b20f93 David Howells 2022-07-06 404 int r;
d2ddc776a4581d David Howells 2017-11-02 405
^1da177e4c3f41 Linus Torvalds 2005-04-16 @406 if (!server)
^^^^^^^
Can this check be deleted?

^1da177e4c3f41 Linus Torvalds 2005-04-16 407 return;
^1da177e4c3f41 Linus Torvalds 2005-04-16 408
2757a4dc184997 David Howells 2022-07-06 409 a = atomic_inc_return(&server->active);
c56f9ec8b20f93 David Howells 2022-07-06 410 zero = __refcount_dec_and_test(&server->ref, &r);
2757a4dc184997 David Howells 2022-07-06 411 trace_afs_server(debug_id, r - 1, a, reason);
c56f9ec8b20f93 David Howells 2022-07-06 412 if (unlikely(zero))
977e5f8ed0ab27 David Howells 2020-04-17 413 __afs_put_server(net, server);
977e5f8ed0ab27 David Howells 2020-04-17 414 }

--
0-DAY CI Kernel Test Service
https://01.org/lkp