Skip to content

Commit fb05028

Browse files
hclee1Naim
authored andcommitted
ntfs: fix variable dereferenced before check warnings
Detected by Smatch. lcnalloc.c:736 ntfs_cluster_alloc() error: we previously assumed 'rl' could be null (see line 719) inode.c:3275 ntfs_inode_close() warn: variable dereferenced before check 'tmp_nis' (see line 3255) attrib.c:4952 ntfs_attr_remove() warn: variable dereferenced before check 'ni' (see line 4951) dir.c:1035 ntfs_readdir() error: we previously assumed 'private' could be null (see line 850) Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 8ea50d3 commit fb05028

5 files changed

Lines changed: 16 additions & 13 deletions

File tree

fs/ntfs/attrib.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,31 +4941,27 @@ int ntfs_attr_exist(struct ntfs_inode *ni, const __le32 type, __le16 *name,
49414941
int ntfs_attr_remove(struct ntfs_inode *ni, const __le32 type, __le16 *name,
49424942
u32 name_len)
49434943
{
4944-
struct super_block *sb;
49454944
int err;
49464945
struct inode *attr_vi;
49474946
struct ntfs_inode *attr_ni;
49484947

49494948
ntfs_debug("Entering\n");
49504949

4951-
sb = ni->vol->sb;
4952-
if (!ni) {
4953-
ntfs_error(sb, "NULL inode pointer\n");
4950+
if (!ni)
49544951
return -EINVAL;
4955-
}
49564952

49574953
attr_vi = ntfs_attr_iget(VFS_I(ni), type, name, name_len);
49584954
if (IS_ERR(attr_vi)) {
49594955
err = PTR_ERR(attr_vi);
4960-
ntfs_error(sb, "Failed to open attribute 0x%02x of inode 0x%llx",
4956+
ntfs_error(ni->vol->sb, "Failed to open attribute 0x%02x of inode 0x%llx",
49614957
type, (unsigned long long)ni->mft_no);
49624958
return err;
49634959
}
49644960
attr_ni = NTFS_I(attr_vi);
49654961

49664962
err = ntfs_attr_rm(attr_ni);
49674963
if (err)
4968-
ntfs_error(sb, "Failed to remove attribute 0x%02x of inode 0x%llx",
4964+
ntfs_error(ni->vol->sb, "Failed to remove attribute 0x%02x of inode 0x%llx",
49694965
type, (unsigned long long)ni->mft_no);
49704966
iput(attr_vi);
49714967
return err;

fs/ntfs/dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,10 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
10321032
}
10331033

10341034
if (err) {
1035-
private->curr_pos = actor->pos;
1036-
private->end_in_iterate = true;
1035+
if (private) {
1036+
private->curr_pos = actor->pos;
1037+
private->end_in_iterate = true;
1038+
}
10371039
err = 0;
10381040
}
10391041
ntfs_index_ctx_put(ictx);

fs/ntfs/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3250,8 +3250,10 @@ int ntfs_inode_close(struct ntfs_inode *ni)
32503250
* base inode before destroying it.
32513251
*/
32523252
base_ni = ni->ext.base_ntfs_ino;
3253+
tmp_nis = base_ni->ext.extent_ntfs_inos;
3254+
if (!tmp_nis)
3255+
goto out;
32533256
for (i = 0; i < base_ni->nr_extents; ++i) {
3254-
tmp_nis = base_ni->ext.extent_ntfs_inos;
32553257
if (tmp_nis[i] != ni)
32563258
continue;
32573259
/* Found it. Disconnect. */
@@ -3279,6 +3281,7 @@ int ntfs_inode_close(struct ntfs_inode *ni)
32793281
break;
32803282
}
32813283

3284+
out:
32823285
if (NInoDirty(ni))
32833286
ntfs_error(ni->vol->sb, "Releasing dirty inode %llu!\n",
32843287
ni->mft_no);

fs/ntfs/lcnalloc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,13 @@ switch_to_data1_zone: search_zone = 2;
732732
folio_put(folio);
733733
}
734734
if (likely(!err)) {
735+
if (!rl) {
736+
err = -EIO;
737+
goto out_restore;
738+
}
735739
if (is_dealloc == true)
736740
ntfs_release_dirty_clusters(vol, rl->length);
737741
ntfs_debug("Done.");
738-
if (rl == NULL)
739-
err = -EIO;
740742
goto out_restore;
741743
}
742744
if (err != -ENOSPC)

fs/ntfs/runlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ struct runlist_element *ntfs_rl_insert_range(struct runlist_element *dst_rl, int
16611661
{
16621662
struct runlist_element *i_rl, *new_rl, *src_rl_origin = src_rl;
16631663
struct runlist_element dst_rl_split;
1664-
s64 start_vcn = src_rl[0].vcn;
1664+
s64 start_vcn;
16651665
int new_1st_cnt, new_2nd_cnt, new_3rd_cnt, new_cnt;
16661666

16671667
if (!dst_rl || !src_rl || !new_rl_cnt)

0 commit comments

Comments
 (0)