]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs: fix variable dereferenced before check ni and attr in ntfs_attrlist_entry_add()
authorNamjae Jeon <linkinjeon@kernel.org>
Fri, 1 May 2026 12:10:38 +0000 (21:10 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Sun, 3 May 2026 01:40:09 +0000 (10:40 +0900)
Smatch warnings:

ntfs_attrlist_entry_add() warn: variable dereferenced before check 'ni'
ntfs_attrlist_entry_add() warn: variable dereferenced before check 'attr'

Moves the ntfs_debug() call after the NULL pointer checks to ensure safe
access to the structure members.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/attrlist.c

index bd501e8a628c470582274ad8f658f1c7664127ec..c2594d4c83b0611e49debb38fa3df3974bb2f8c1 100644 (file)
@@ -119,15 +119,14 @@ int ntfs_attrlist_entry_add(struct ntfs_inode *ni, struct attr_record *attr)
        struct mft_record *ni_mrec;
        u8 *old_al;
 
-       ntfs_debug("Entering for inode 0x%llx, attr 0x%x.\n",
-                       (long long) ni->mft_no,
-                       (unsigned int) le32_to_cpu(attr->type));
-
        if (!ni || !attr) {
                ntfs_debug("Invalid arguments.\n");
                return -EINVAL;
        }
 
+       ntfs_debug("Entering for inode 0x%llx, attr 0x%x.\n",
+                       ni->mft_no, (unsigned int) le32_to_cpu(attr->type));
+
        ni_mrec = map_mft_record(ni);
        if (IS_ERR(ni_mrec)) {
                ntfs_debug("Invalid arguments.\n");