fs/ntfs3: Fix sparse problems
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 6 Oct 2022 16:58:11 +0000 (19:58 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Mon, 14 Nov 2022 16:50:42 +0000 (19:50 +0300)
Fixing various problems, detected by sparse.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/attrib.c
fs/ntfs3/dir.c
fs/ntfs3/frecord.c
fs/ntfs3/namei.c

index 63169529b52c499dbbc3d2144e794935ca6b3194..b2f54fab40012c398daaf1d100cfca48ca8fe84d 100644 (file)
@@ -2308,7 +2308,8 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
 
                if (!attr_b->non_res) {
                        /* Still resident. */
-                       char *data = Add2Ptr(attr_b, attr_b->res.data_off);
+                       char *data = Add2Ptr(attr_b,
+                                            le16_to_cpu(attr_b->res.data_off));
 
                        memmove(data + bytes, data, bytes);
                        memset(data, 0, bytes);
@@ -2400,8 +2401,8 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
        if (vbo <= ni->i_valid)
                ni->i_valid += bytes;
 
-       attr_b->nres.data_size = le64_to_cpu(data_size + bytes);
-       attr_b->nres.alloc_size = le64_to_cpu(alloc_size + bytes);
+       attr_b->nres.data_size = cpu_to_le64(data_size + bytes);
+       attr_b->nres.alloc_size = cpu_to_le64(alloc_size + bytes);
 
        /* ni->valid may be not equal valid_size (temporary). */
        if (ni->i_valid > data_size + bytes)
index fb438d6040409838389ba7454645034ab2fa7a08..063a6654199bc078074e2b85f34ce1f31d93a197 100644 (file)
@@ -26,8 +26,8 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const __le16 *name, u32 len,
 
        if (!nls) {
                /* UTF-16 -> UTF-8 */
-               ret = utf16s_to_utf8s(name, len, UTF16_LITTLE_ENDIAN, buf,
-                                     buf_len);
+               ret = utf16s_to_utf8s((wchar_t *)name, len, UTF16_LITTLE_ENDIAN,
+                                     buf, buf_len);
                buf[ret] = '\0';
                return ret;
        }
index 039247ab5b0b72c72fb9a48fefefab8742f1db8c..ff938d3cd5efe6d6097a648c7087373dbef4b460 100644 (file)
@@ -1670,8 +1670,7 @@ next:
                goto next;
 
        fns = (struct le_str *)&fname->name_len;
-       if (ntfs_cmp_names(uni->name, uni->len, fns->name, fns->len, NULL,
-                              false))
+       if (ntfs_cmp_names_cpu(uni, fns, NULL, false))
                goto next;
 
        return fname;
index 6b0d2c01d6ffc3071ba562683efb8a314ed26f1a..ad6d16dec9f0675b65684642fb3c21ba6c045ea6 100644 (file)
@@ -427,7 +427,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
        unsigned int len2 = name->len;
        unsigned int lm = min(len1, len2);
        unsigned char c1, c2;
-       struct cpu_str *uni1, *uni2;
+       struct cpu_str *uni1;
+       struct le_str *uni2;
 
        /* First try fast implementation. */
        for (;;) {
@@ -464,8 +465,9 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 
        uni2 = Add2Ptr(uni1, 2048);
 
-       ret = ntfs_nls_to_utf16(sbi, name->name, name->len, uni2, NTFS_NAME_LEN,
-                               UTF16_HOST_ENDIAN);
+       ret = ntfs_nls_to_utf16(sbi, name->name, name->len,
+                               (struct cpu_str *)uni2, NTFS_NAME_LEN,
+                               UTF16_LITTLE_ENDIAN);
        if (ret < 0)
                goto out;
 
@@ -474,10 +476,7 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
                goto out;
        }
 
-       ret = !ntfs_cmp_names(uni1->name, uni1->len, uni2->name, uni2->len,
-                             sbi->upcase, false)
-                     ? 0
-                     : 1;
+       ret = !ntfs_cmp_names_cpu(uni1, uni2, sbi->upcase, false) ? 0 : 1;
 
 out:
        __putname(uni1);