fs/smb/client/dfs_cache.c:750 cache_refresh_path() warn: inconsistent returns '&htable_rw_lock'.

From: Dan Carpenter
Date: Mon Jul 24 2023 - 03:49:07 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 295e1388de2d5c0c354adbd65d0319c5d636c222
commit: 38c8a9a52082579090e34c033d439ed2cd1a462d smb: move client and server files to common directory fs/smb
config: i386-randconfig-m021-20230723 (https://download.01.org/0day-ci/archive/20230723/202307231110.D2DlDq9B-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230723/202307231110.D2DlDq9B-lkp@xxxxxxxxx/reproduce)

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>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202307231110.D2DlDq9B-lkp@xxxxxxxxx/

New smatch warnings:
fs/smb/client/dfs_cache.c:750 cache_refresh_path() warn: inconsistent returns '&htable_rw_lock'.

Old smatch warnings:
fs/smb/client/dfs_cache.c:403 copy_ref_data() warn: passing a valid pointer to 'PTR_ERR'

vim +750 fs/smb/client/dfs_cache.c

48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 685 static struct cache_entry *cache_refresh_path(const unsigned int xid,
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 686 struct cifs_ses *ses,
8064f711c6a461 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 687 const char *path,
8064f711c6a461 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 688 bool force_refresh)
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 689 {
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 690) struct dfs_info3_param *refs = NULL;
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 691 struct cache_entry *ce;
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 692) int numrefs = 0;
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 693 int rc;
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 694
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 695 cifs_dbg(FYI, "%s: search path: %s\n", __func__, path);
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 696
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 697 down_read(&htable_rw_lock);
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 698)
42caeba713b12e fs/cifs/dfs_cache.c Paulo Alcantara 2021-06-04 699 ce = lookup_cache_entry(path);
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 700 if (!IS_ERR(ce)) {
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 701 if (!force_refresh && !cache_entry_expired(ce))
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 702 return ce;

Call up_read(&htable_rw_lock) before returning

3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 703 } else if (PTR_ERR(ce) != -ENOENT) {
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 704 up_read(&htable_rw_lock);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 705 return ce;
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 706 }
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 707
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 708 /*
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 709 * Unlock shared access as we don't want to hold any locks while getting
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 710 * a new referral. The @ses used for performing the I/O could be
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 711 * reconnecting and it acquires @htable_rw_lock to look up the dfs cache
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 712 * in order to failover -- if necessary.
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 713 */
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 714 up_read(&htable_rw_lock);
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 715
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 716) /*
8064f711c6a461 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 717 * Either the entry was not found, or it is expired, or it is a forced
8064f711c6a461 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 718 * refresh.
c9f71103990591 fs/cifs/dfs_cache.c Paulo Alcantara 2021-06-04 719 * Request a new DFS referral in order to create or update a cache entry.
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 720) */
c870a8e70e6827 fs/cifs/dfs_cache.c Paulo Alcantara 2021-06-04 721 rc = get_dfs_referral(xid, ses, path, &refs, &numrefs);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 722 if (rc) {
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 723 ce = ERR_PTR(rc);
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 724 goto out;
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 725 }
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 726
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 727) dump_refs(refs, numrefs);
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 728
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 729 down_write(&htable_rw_lock);
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 730 /* Re-check as another task might have it added or refreshed already */
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 731 ce = lookup_cache_entry(path);
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 732 if (!IS_ERR(ce)) {
8064f711c6a461 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 733 if (force_refresh || cache_entry_expired(ce)) {
1023e90b733acd fs/cifs/dfs_cache.c Paulo Alcantara 2021-06-08 734 rc = update_cache_entry_locked(ce, refs, numrefs);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 735 if (rc)
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 736 ce = ERR_PTR(rc);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 737 }
3deddb77fdd932 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 738 } else if (PTR_ERR(ce) == -ENOENT) {
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 739 ce = add_cache_entry_locked(refs, numrefs);
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 740 }
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 741
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 742 if (IS_ERR(ce)) {
c9f71103990591 fs/cifs/dfs_cache.c Paulo Alcantara 2021-06-04 743 up_write(&htable_rw_lock);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 744 goto out;
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 745 }
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 746
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 747 downgrade_write(&htable_rw_lock);
9fb0db40513e27 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 748 out:
742d8de0186e9f fs/cifs/dfs_cache.c Paulo Alcantara (SUSE 2019-12-04 749) free_dfs_info_array(refs, numrefs);
48d240bf00af94 fs/cifs/dfs_cache.c Paulo Alcantara 2023-01-17 @750 return ce;
54be1f6c1c3749 fs/cifs/dfs_cache.c Paulo Alcantara 2018-11-14 751 }

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