fs/smb/server/connection.c:42:5-24: WARNING: atomic_dec_and_test variation before object free at line 43.

From: kernel test robot
Date: Sat Jun 28 2025 - 07:21:01 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: aaf724ed69264719550ec4f194d3ab17b886af9a
commit: ee426bfb9d09b29987369b897fe9b6485ac2be27 ksmbd: add refcnt to ksmbd_conn struct
date: 10 months ago
config: i386-randconfig-052-20250628 (https://download.01.org/0day-ci/archive/20250628/202506281916.wVorCT8Y-lkp@xxxxxxxxx/config)
compiler: clang version 20.1.7 (https://github.com/llvm/llvm-project 6146a88f60492b520a36f8f8f3231e15f3cc6082)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506281916.wVorCT8Y-lkp@xxxxxxxxx/

cocci warnings: (new ones prefixed by >>)
>> fs/smb/server/connection.c:42:5-24: WARNING: atomic_dec_and_test variation before object free at line 43.

vim +42 fs/smb/server/connection.c

24
25 /**
26 * ksmbd_conn_free() - free resources of the connection instance
27 *
28 * @conn: connection instance to be cleand up
29 *
30 * During the thread termination, the corresponding conn instance
31 * resources(sock/memory) are released and finally the conn object is freed.
32 */
33 void ksmbd_conn_free(struct ksmbd_conn *conn)
34 {
35 down_write(&conn_list_lock);
36 list_del(&conn->conns_list);
37 up_write(&conn_list_lock);
38
39 xa_destroy(&conn->sessions);
40 kvfree(conn->request_buf);
41 kfree(conn->preauth_info);
> 42 if (atomic_dec_and_test(&conn->refcnt))
> 43 kfree(conn);
44 }
45

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki