[linux-next:master 9898/11507] fs/ntfs3/inode.c:570 ntfs_init_ads_node() error: we previously assumed 'attr' could be null (see line 555)

kernel test robot <[email protected]> Sat, 01 Aug 2026 07:29:16 +0800
Newsgroups dev.linux.lists.oe-kbuild
Message-ID <[email protected]>
BCC: [email protected]
CC: [email protected]
TO: Konstantin Komarov <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   415606a7be939835db9b0d6b711887586646346d
commit: be310476e8868ebe7a2ce8fb0e7b229535723963 [9898/11507] fs/ntfs3: Add basic support for alternative data streams
:::::: branch date: 7 hours ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-161 (https://download.01.org/0day-ci/archive/20260801/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
smatch: v0.5.0-9187-g5189e3fb

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]/

smatch warnings:
fs/ntfs3/inode.c:570 ntfs_init_ads_node() error: we previously assumed 'attr' could be null (see line 555)

vim +/attr +570 fs/ntfs3/inode.c

be310476e8868e Konstantin Komarov 2026-07-30  515  
be310476e8868e Konstantin Komarov 2026-07-30  516  /*
be310476e8868e Konstantin Komarov 2026-07-30  517   * ntfs_init_ads_node
be310476e8868e Konstantin Komarov 2026-07-30  518   *
be310476e8868e Konstantin Komarov 2026-07-30  519   * This function scans base inode for given ADS.
be310476e8868e Konstantin Komarov 2026-07-30  520   * And init inode associated with this ADS
be310476e8868e Konstantin Komarov 2026-07-30  521   */
be310476e8868e Konstantin Komarov 2026-07-30  522  static int ntfs_init_ads_node(struct inode *inode, const __le16 *ads_name,
be310476e8868e Konstantin Komarov 2026-07-30  523  			      u8 ads_len, u32 flags)
be310476e8868e Konstantin Komarov 2026-07-30  524  {
be310476e8868e Konstantin Komarov 2026-07-30  525  	int err = -EINVAL;
be310476e8868e Konstantin Komarov 2026-07-30  526  	struct ntfs_inode *ni = ntfs_i(inode);
be310476e8868e Konstantin Komarov 2026-07-30  527  	struct ntfs_inode *nb = ni->base;
be310476e8868e Konstantin Komarov 2026-07-30  528  	struct ntfs_sb_info *sbi = nb->mi.sbi;
be310476e8868e Konstantin Komarov 2026-07-30  529  	struct ATTR_LIST_ENTRY *le = NULL;
be310476e8868e Konstantin Komarov 2026-07-30  530  	struct ATTRIB *attr = NULL;
be310476e8868e Konstantin Komarov 2026-07-30  531  	u16 roff, asize;
be310476e8868e Konstantin Komarov 2026-07-30  532  	u64 svcn;
be310476e8868e Konstantin Komarov 2026-07-30  533  
be310476e8868e Konstantin Komarov 2026-07-30  534  	if (nb->ni_flags & NI_FLAG_DIR)
be310476e8868e Konstantin Komarov 2026-07-30  535  		return -EINVAL; /* no ADS for directories. */
be310476e8868e Konstantin Komarov 2026-07-30  536  
be310476e8868e Konstantin Komarov 2026-07-30  537  	ni->mi.sbi = sbi;
be310476e8868e Konstantin Komarov 2026-07-30  538  	ni->mi.rno = inode->i_ino;
be310476e8868e Konstantin Komarov 2026-07-30  539  
be310476e8868e Konstantin Komarov 2026-07-30  540  	if (ads_len == ARRAY_SIZE(QUERY_STREAMS) &&
be310476e8868e Konstantin Komarov 2026-07-30  541  	    !memcmp(ads_name, QUERY_STREAMS, sizeof(QUERY_STREAMS))) {
be310476e8868e Konstantin Komarov 2026-07-30  542  		goto ok; /* use goto to reduce tab pressure. */
be310476e8868e Konstantin Komarov 2026-07-30  543  	}
be310476e8868e Konstantin Komarov 2026-07-30  544  
be310476e8868e Konstantin Komarov 2026-07-30  545  	/* Enumerate all attributes in record. */
be310476e8868e Konstantin Komarov 2026-07-30  546  	while ((attr = ni_enum_attr_ex(nb, attr, &le, NULL))) {
be310476e8868e Konstantin Komarov 2026-07-30  547  		if (attr->type == ATTR_DATA && attr->name_len &&
be310476e8868e Konstantin Komarov 2026-07-30  548  		    ads_len == attr->name_len &&
be310476e8868e Konstantin Komarov 2026-07-30  549  		    !memcmp(ads_name, attr_name(attr), ads_len * sizeof(u16))) {
be310476e8868e Konstantin Komarov 2026-07-30  550  			/* We have found the ADS to open. */
be310476e8868e Konstantin Komarov 2026-07-30  551  			break;
be310476e8868e Konstantin Komarov 2026-07-30  552  		}
be310476e8868e Konstantin Komarov 2026-07-30  553  	}
be310476e8868e Konstantin Komarov 2026-07-30  554  
be310476e8868e Konstantin Komarov 2026-07-30 @555  	if (!attr) {
be310476e8868e Konstantin Komarov 2026-07-30  556  		if (!(flags & LOOKUP_CREATE)) {
be310476e8868e Konstantin Komarov 2026-07-30  557  			/* Do not create ADS. */
be310476e8868e Konstantin Komarov 2026-07-30  558  			return -ENOENT;
be310476e8868e Konstantin Komarov 2026-07-30  559  		}
be310476e8868e Konstantin Komarov 2026-07-30  560  
be310476e8868e Konstantin Komarov 2026-07-30  561  		/* Create new ADS. */
be310476e8868e Konstantin Komarov 2026-07-30  562  		err = ni_insert_resident(nb, 0, ATTR_DATA, ads_name, ads_len,
be310476e8868e Konstantin Komarov 2026-07-30  563  					 &attr, NULL, NULL);
be310476e8868e Konstantin Komarov 2026-07-30  564  		if (err) {
be310476e8868e Konstantin Komarov 2026-07-30  565  			/* Looks like the only reasons: ENOSPC/ENOMEM .*/
be310476e8868e Konstantin Komarov 2026-07-30  566  			return err;
be310476e8868e Konstantin Komarov 2026-07-30  567  		}
be310476e8868e Konstantin Komarov 2026-07-30  568  	}
be310476e8868e Konstantin Komarov 2026-07-30  569  
be310476e8868e Konstantin Komarov 2026-07-30 @570  	if (is_attr_sparsed(attr))
be310476e8868e Konstantin Komarov 2026-07-30  571  		ni->std_fa |= FILE_ATTRIBUTE_SPARSE_FILE;
be310476e8868e Konstantin Komarov 2026-07-30  572  	else
be310476e8868e Konstantin Komarov 2026-07-30  573  		ni->std_fa &= ~FILE_ATTRIBUTE_SPARSE_FILE;
be310476e8868e Konstantin Komarov 2026-07-30  574  
be310476e8868e Konstantin Komarov 2026-07-30  575  	if (is_attr_compressed(attr))
be310476e8868e Konstantin Komarov 2026-07-30  576  		ni->std_fa |= FILE_ATTRIBUTE_COMPRESSED;
be310476e8868e Konstantin Komarov 2026-07-30  577  	else
be310476e8868e Konstantin Komarov 2026-07-30  578  		ni->std_fa &= ~FILE_ATTRIBUTE_COMPRESSED;
be310476e8868e Konstantin Komarov 2026-07-30  579  
be310476e8868e Konstantin Komarov 2026-07-30  580  	if (is_attr_encrypted(attr))
be310476e8868e Konstantin Komarov 2026-07-30  581  		ni->std_fa |= FILE_ATTRIBUTE_ENCRYPTED;
be310476e8868e Konstantin Komarov 2026-07-30  582  	else
be310476e8868e Konstantin Komarov 2026-07-30  583  		ni->std_fa &= ~FILE_ATTRIBUTE_ENCRYPTED;
be310476e8868e Konstantin Komarov 2026-07-30  584  
be310476e8868e Konstantin Komarov 2026-07-30  585  	if (!attr->non_res) {
be310476e8868e Konstantin Komarov 2026-07-30  586  		ni->ni_flags |= NI_FLAG_RESIDENT;
be310476e8868e Konstantin Komarov 2026-07-30  587  		ni->i_valid = inode->i_size = le32_to_cpu(attr->res.data_size);
be310476e8868e Konstantin Komarov 2026-07-30  588  		inode_set_bytes(inode, inode->i_size);
be310476e8868e Konstantin Komarov 2026-07-30  589  		goto ok;
be310476e8868e Konstantin Komarov 2026-07-30  590  	}
be310476e8868e Konstantin Komarov 2026-07-30  591  
be310476e8868e Konstantin Komarov 2026-07-30  592  	inode_set_bytes(inode, attr_ondisk_size(attr));
be310476e8868e Konstantin Komarov 2026-07-30  593  	ni->i_valid = le64_to_cpu(attr->nres.valid_size);
be310476e8868e Konstantin Komarov 2026-07-30  594  	inode->i_size = le64_to_cpu(attr->nres.data_size);
be310476e8868e Konstantin Komarov 2026-07-30  595  
be310476e8868e Konstantin Komarov 2026-07-30  596  	if (!attr->nres.alloc_size)
be310476e8868e Konstantin Komarov 2026-07-30  597  		goto ok;
be310476e8868e Konstantin Komarov 2026-07-30  598  
be310476e8868e Konstantin Komarov 2026-07-30  599  	roff = le16_to_cpu(attr->nres.run_off);
be310476e8868e Konstantin Komarov 2026-07-30  600  	asize = le32_to_cpu(attr->size);
be310476e8868e Konstantin Komarov 2026-07-30  601  
be310476e8868e Konstantin Komarov 2026-07-30  602  	if (roff > asize) {
be310476e8868e Konstantin Komarov 2026-07-30  603  		/* This case should be checked in mi_enum_attr */
be310476e8868e Konstantin Komarov 2026-07-30  604  		return -EINVAL;
be310476e8868e Konstantin Komarov 2026-07-30  605  	}
be310476e8868e Konstantin Komarov 2026-07-30  606  
be310476e8868e Konstantin Komarov 2026-07-30  607  	svcn = le64_to_cpu(attr->nres.svcn);
be310476e8868e Konstantin Komarov 2026-07-30  608  	err = run_unpack_ex(&ni->file.run, sbi, ni->mi.rno, svcn,
be310476e8868e Konstantin Komarov 2026-07-30  609  			    le64_to_cpu(attr->nres.evcn), svcn,
be310476e8868e Konstantin Komarov 2026-07-30  610  			    Add2Ptr(attr, roff), asize - roff);
be310476e8868e Konstantin Komarov 2026-07-30  611  	if (err < 0) {
be310476e8868e Konstantin Komarov 2026-07-30  612  		/* run_unpack_ex marks volume dirty, if logical error. */
be310476e8868e Konstantin Komarov 2026-07-30  613  		return err;
be310476e8868e Konstantin Komarov 2026-07-30  614  	}
be310476e8868e Konstantin Komarov 2026-07-30  615  
be310476e8868e Konstantin Komarov 2026-07-30  616  ok:
be310476e8868e Konstantin Komarov 2026-07-30  617  	/* Keep ADS name (little endian). */
be310476e8868e Konstantin Komarov 2026-07-30  618  	ni->file.ads.name = kmemdup(ads_name, ads_len * sizeof(u16), GFP_NOFS);
be310476e8868e Konstantin Komarov 2026-07-30  619  	if (!ni->file.ads.name)
be310476e8868e Konstantin Komarov 2026-07-30  620  		return -ENOMEM;
be310476e8868e Konstantin Komarov 2026-07-30  621  	ni->file.ads.len = ads_len;
be310476e8868e Konstantin Komarov 2026-07-30  622  
be310476e8868e Konstantin Komarov 2026-07-30  623  	set_nlink(inode, 1);
be310476e8868e Konstantin Komarov 2026-07-30  624  
be310476e8868e Konstantin Komarov 2026-07-30  625  	init_rwsem(&ni->file.run_lock);
be310476e8868e Konstantin Komarov 2026-07-30  626  	/* Most fields are the same as the base's? */
be310476e8868e Konstantin Komarov 2026-07-30  627  	inode->i_op = nb->vfs_inode.i_op;
be310476e8868e Konstantin Komarov 2026-07-30  628  	inode->i_fop = nb->vfs_inode.i_fop;
be310476e8868e Konstantin Komarov 2026-07-30  629  	inode->i_mapping->a_ops = nb->vfs_inode.i_mapping->a_ops;
be310476e8868e Konstantin Komarov 2026-07-30  630  	inode->i_flags = nb->vfs_inode.i_flags;
be310476e8868e Konstantin Komarov 2026-07-30  631  	inode->i_mode = nb->vfs_inode.i_mode;
be310476e8868e Konstantin Komarov 2026-07-30  632  	inode->i_uid = nb->vfs_inode.i_uid;
be310476e8868e Konstantin Komarov 2026-07-30  633  	inode->i_gid = nb->vfs_inode.i_gid;
be310476e8868e Konstantin Komarov 2026-07-30  634  	inode->i_generation = nb->vfs_inode.i_generation;
be310476e8868e Konstantin Komarov 2026-07-30  635  
be310476e8868e Konstantin Komarov 2026-07-30  636  	return 0;
82cae269cfa953 Konstantin Komarov 2021-08-13  637  }
82cae269cfa953 Konstantin Komarov 2021-08-13  638  

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