Skip to contentSkip to conversation

fs/exfat/dir.c:896 __exfat_get_dentry_set() warn: missing unwind goto?

PATCH In review Dan Carpenter 2 participants 2 messages Mar 15, 2024 – Mar 18, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 12881/13613 fs/exfat/dir.c:896 __exfat_get_dentry_set() warn: missing unwind goto?

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   9bb9b28d0568991b1d63e66fe75afa5f97ad1156
commit: bd31db2fd3bdaca4be598ddc39770eb6ebd9e3f3 [12881/13613] exfat: add __exfat_get_dentry_set() helper
config: i386-randconfig-141-20240313 (https://download.01.org/0day-ci/archive/20240315/[email protected]/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
fs/exfat/dir.c:896 __exfat_get_dentry_set() warn: missing unwind goto?

vim +896 fs/exfat/dir.c

bd31db2fd3bdac Yuezhang Mo      2023-12-08  849  static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es,
20914ff6dd56dd Yuezhang Mo      2022-11-17  850  		struct super_block *sb, struct exfat_chain *p_dir, int entry,
bd31db2fd3bdac Yuezhang Mo      2023-12-08  851  		unsigned int num_entries)
ca06197382bde0 Namjae Jeon      2020-03-02  852  {
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  853  	int ret, i, num_bh;
36955d368dc101 Yuezhang Mo      2022-11-17  854  	unsigned int off;
ca06197382bde0 Namjae Jeon      2020-03-02  855  	sector_t sec;
ca06197382bde0 Namjae Jeon      2020-03-02  856  	struct exfat_sb_info *sbi = EXFAT_SB(sb);
ca06197382bde0 Namjae Jeon      2020-03-02  857  	struct buffer_head *bh;
ca06197382bde0 Namjae Jeon      2020-03-02  858  
ca06197382bde0 Namjae Jeon      2020-03-02  859  	if (p_dir->dir == DIR_DELETED) {
d1727d55c0327e Joe Perches      2020-04-24  860  		exfat_err(sb, "access to deleted dentry");
20914ff6dd56dd Yuezhang Mo      2022-11-17  861  		return -EIO;
ca06197382bde0 Namjae Jeon      2020-03-02  862  	}
ca06197382bde0 Namjae Jeon      2020-03-02  863  
36955d368dc101 Yuezhang Mo      2022-11-17  864  	ret = exfat_find_location(sb, p_dir, entry, &sec, &off);
ca06197382bde0 Namjae Jeon      2020-03-02  865  	if (ret)
20914ff6dd56dd Yuezhang Mo      2022-11-17  866  		return ret;
ca06197382bde0 Namjae Jeon      2020-03-02  867  
20914ff6dd56dd Yuezhang Mo      2022-11-17  868  	memset(es, 0, sizeof(*es));
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  869  	es->sb = sb;
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  870  	es->modified = false;
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  871  	es->start_off = off;
a3ff29a95fde16 Yuezhang Mo      2022-11-09  872  	es->bh = es->__bh;
ca06197382bde0 Namjae Jeon      2020-03-02  873  
ca06197382bde0 Namjae Jeon      2020-03-02  874  	bh = sb_bread(sb, sec);
ca06197382bde0 Namjae Jeon      2020-03-02  875  	if (!bh)
20914ff6dd56dd Yuezhang Mo      2022-11-17  876  		return -EIO;
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  877  	es->bh[es->num_bh++] = bh;
ca06197382bde0 Namjae Jeon      2020-03-02  878  
bd31db2fd3bdac Yuezhang Mo      2023-12-08  879  	if (num_entries == ES_ALL_ENTRIES) {
bd31db2fd3bdac Yuezhang Mo      2023-12-08  880  		struct exfat_dentry *ep;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  881  
f3fe3954c09f97 Yuezhang Mo      2022-03-17  882  		ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
bd31db2fd3bdac Yuezhang Mo      2023-12-08  883  		if (ep->type != EXFAT_FILE)
3b9681acb0ef73 Yuezhang Mo      2022-03-17  884  			goto put_es;
                                                                        ^^^^^^^^^^^^
ca06197382bde0 Namjae Jeon      2020-03-02  885  
bd31db2fd3bdac Yuezhang Mo      2023-12-08  886  		num_entries = ep->dentry.file.num_ext + 1;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  887  	}
bd31db2fd3bdac Yuezhang Mo      2023-12-08  888  
ca06197382bde0 Namjae Jeon      2020-03-02  889  	es->num_entries = num_entries;
ca06197382bde0 Namjae Jeon      2020-03-02  890  
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  891  	num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb);
a3ff29a95fde16 Yuezhang Mo      2022-11-09  892  	if (num_bh > ARRAY_SIZE(es->__bh)) {
a3ff29a95fde16 Yuezhang Mo      2022-11-09  893  		es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
a3ff29a95fde16 Yuezhang Mo      2022-11-09  894  		if (!es->bh) {
a3ff29a95fde16 Yuezhang Mo      2022-11-09  895  			brelse(bh);

20914ff6dd56dd Yuezhang Mo 2022-11-17 @896 return -ENOMEM;

I normally wouldn't send this because it's not a bug, but actually other people are going to see this static checker warning and the code is slightly confusing.

At this point calling brelse(bh) and calling exfat_put_dentry_set(es, false); are equivalent. So the code works. But it would be better to do things consistently on both lines 884 and 896.

a3ff29a95fde16 Yuezhang Mo      2022-11-09  897  		}
a3ff29a95fde16 Yuezhang Mo      2022-11-09  898  		es->bh[0] = bh;
a3ff29a95fde16 Yuezhang Mo      2022-11-09  899  	}
a3ff29a95fde16 Yuezhang Mo      2022-11-09  900  
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  901  	for (i = 1; i < num_bh; i++) {
ca06197382bde0 Namjae Jeon      2020-03-02  902  		/* get the next sector */
ca06197382bde0 Namjae Jeon      2020-03-02  903  		if (exfat_is_last_sector_in_cluster(sbi, sec)) {
36955d368dc101 Yuezhang Mo      2022-11-17  904  			unsigned int clu = exfat_sector_to_cluster(sbi, sec);
36955d368dc101 Yuezhang Mo      2022-11-17  905  
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  906  			if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
ca06197382bde0 Namjae Jeon      2020-03-02  907  				clu++;
ca06197382bde0 Namjae Jeon      2020-03-02  908  			else if (exfat_get_next_cluster(sb, &clu))
3b9681acb0ef73 Yuezhang Mo      2022-03-17  909  				goto put_es;
ca06197382bde0 Namjae Jeon      2020-03-02  910  			sec = exfat_cluster_to_sector(sbi, clu);
ca06197382bde0 Namjae Jeon      2020-03-02  911  		} else {
ca06197382bde0 Namjae Jeon      2020-03-02  912  			sec++;
ca06197382bde0 Namjae Jeon      2020-03-02  913  		}
ca06197382bde0 Namjae Jeon      2020-03-02  914  
ca06197382bde0 Namjae Jeon      2020-03-02  915  		bh = sb_bread(sb, sec);
ca06197382bde0 Namjae Jeon      2020-03-02  916  		if (!bh)
3b9681acb0ef73 Yuezhang Mo      2022-03-17  917  			goto put_es;
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  918  		es->bh[es->num_bh++] = bh;
ca06197382bde0 Namjae Jeon      2020-03-02  919  	}
ca06197382bde0 Namjae Jeon      2020-03-02  920  
bd31db2fd3bdac Yuezhang Mo      2023-12-08  921  	return 0;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  922  
bd31db2fd3bdac Yuezhang Mo      2023-12-08  923  put_es:
bd31db2fd3bdac Yuezhang Mo      2023-12-08  924  	exfat_put_dentry_set(es, false);
bd31db2fd3bdac Yuezhang Mo      2023-12-08  925  	return -EIO;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  926  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 16 lines
f3fe3954c09f97 Yuezhang Mo      2022-03-17  882                 ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
bd31db2fd3bdac Yuezhang Mo      2023-12-08  883                 if (ep->type != EXFAT_FILE)
3b9681acb0ef73 Yuezhang Mo      2022-03-17  884                         goto put_es;
                                                                       ^^^^^^^^^^^^>
ca06197382bde0 Namjae Jeon      2020-03-02  885
bd31db2fd3bdac Yuezhang Mo      2023-12-08  886                 num_entries = ep->dentry.file.num_ext + 1;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  887         }
bd31db2fd3bdac Yuezhang Mo      2023-12-08  888
ca06197382bde0 Namjae Jeon      2020-03-02  889         es->num_entries = num_entries;
ca06197382bde0 Namjae Jeon      2020-03-02  890
943af1fdacfebe Tetsuhiro Kohada 2020-05-20  891         num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb);
a3ff29a95fde16 Yuezhang Mo      2022-11-09  892         if (num_bh > ARRAY_SIZE(es->__bh)) {
a3ff29a95fde16 Yuezhang Mo      2022-11-09  893                 es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
a3ff29a95fde16 Yuezhang Mo      2022-11-09  894                 if (!es->bh) {
a3ff29a95fde16 Yuezhang Mo      2022-11-09  895                         brelse(bh);
Quoted 4 lines

20914ff6dd56dd Yuezhang Mo 2022-11-17 @896 return -ENOMEM;

I normally wouldn't send this because it's not a bug, but actually other people are going to see this static checker warning and the code is

slightly confusing.

Quoted 5 lines

At this point calling brelse(bh) and calling exfat_put_dentry_set(es, false); are equivalent. So the code works. But it would be better to do things consistently on both lines 884 and 896.

Yes, it is a good point.

But at this point calling brelse(bh) and calling exfat_put_dentry_set(es, false); are not equivalent, because "es->bh" is NULL.

To be consistent on lines 884 and 896, I'll change line 884 to call brelse(bh).

Quoted 5 lines
bd31db2fd3bdac Yuezhang Mo      2023-12-08  923  put_es:
bd31db2fd3bdac Yuezhang Mo      2023-12-08  924         exfat_put_dentry_set(es, false);
bd31db2fd3bdac Yuezhang Mo      2023-12-08  925         return -EIO;
bd31db2fd3bdac Yuezhang Mo      2023-12-08  926  }