]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ext4: Move CONFIG_UNICODE defguards into the code flow
authorGabriel Krisman Bertazi <krisman@collabora.com>
Thu, 6 Jun 2024 07:33:52 +0000 (10:33 +0300)
committerChristian Brauner <brauner@kernel.org>
Fri, 7 Jun 2024 15:00:45 +0000 (17:00 +0200)
Instead of a bunch of ifdefs, make the unicode built checks part of the
code flow where possible, as requested by Torvalds.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
[eugen.hristev@collabora.com: port to 6.10-rc1]
Signed-off-by: Eugen Hristev <eugen.hristev@collabora.com>
Link: https://lore.kernel.org/r/20240606073353.47130-7-eugen.hristev@collabora.com
Reviewed-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/ext4/crypto.c
fs/ext4/ext4.h
fs/ext4/namei.c
fs/ext4/super.c

index 7ae0b61258a7fc69f1bad42992fbbe09c2c80e28..0a056d97e64024a3aa47a86d87a3b9fddbe700df 100644 (file)
@@ -31,11 +31,10 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
 
        ext4_fname_from_fscrypt_name(fname, &name);
 
-#if IS_ENABLED(CONFIG_UNICODE)
        err = ext4_fname_setup_ci_filename(dir, iname, fname);
        if (err)
                ext4_fname_free_filename(fname);
-#endif
+
        return err;
 }
 
@@ -51,11 +50,9 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,
 
        ext4_fname_from_fscrypt_name(fname, &name);
 
-#if IS_ENABLED(CONFIG_UNICODE)
        err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname);
        if (err)
                ext4_fname_free_filename(fname);
-#endif
        return err;
 }
 
@@ -70,10 +67,7 @@ void ext4_fname_free_filename(struct ext4_filename *fname)
        fname->usr_fname = NULL;
        fname->disk_name.name = NULL;
 
-#if IS_ENABLED(CONFIG_UNICODE)
-       kfree(fname->cf_name.name);
-       fname->cf_name.name = NULL;
-#endif
+       ext4_fname_free_ci_filename(fname);
 }
 
 static bool uuid_is_zero(__u8 u[16])
index deffd7431c8bf549bcc94dd02c407db094513873..8007abd4972dc40913650fbd0aa6732ffd365b06 100644 (file)
@@ -2745,8 +2745,25 @@ ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
 
 #if IS_ENABLED(CONFIG_UNICODE)
 extern int ext4_fname_setup_ci_filename(struct inode *dir,
-                                        const struct qstr *iname,
-                                        struct ext4_filename *fname);
+                                       const struct qstr *iname,
+                                       struct ext4_filename *fname);
+
+static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname)
+{
+       kfree(fname->cf_name.name);
+       fname->cf_name.name = NULL;
+}
+#else
+static inline int ext4_fname_setup_ci_filename(struct inode *dir,
+                                              const struct qstr *iname,
+                                              struct ext4_filename *fname)
+{
+       return 0;
+}
+
+static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname)
+{
+}
 #endif
 
 /* ext4 encryption related stuff goes here crypto.c */
@@ -2769,16 +2786,11 @@ static inline int ext4_fname_setup_filename(struct inode *dir,
                                            int lookup,
                                            struct ext4_filename *fname)
 {
-       int err = 0;
        fname->usr_fname = iname;
        fname->disk_name.name = (unsigned char *) iname->name;
        fname->disk_name.len = iname->len;
 
-#if IS_ENABLED(CONFIG_UNICODE)
-       err = ext4_fname_setup_ci_filename(dir, iname, fname);
-#endif
-
-       return err;
+       return ext4_fname_setup_ci_filename(dir, iname, fname);
 }
 
 static inline int ext4_fname_prepare_lookup(struct inode *dir,
@@ -2790,10 +2802,7 @@ static inline int ext4_fname_prepare_lookup(struct inode *dir,
 
 static inline void ext4_fname_free_filename(struct ext4_filename *fname)
 {
-#if IS_ENABLED(CONFIG_UNICODE)
-       kfree(fname->cf_name.name);
-       fname->cf_name.name = NULL;
-#endif
+       ext4_fname_free_ci_filename(fname);
 }
 
 static inline int ext4_ioctl_get_encryption_pwsalt(struct file *filp,
index d10ea0f3f64dffe2b9fb2a8a73c25d85fd17b2a5..e6769b97a970af41fcd15c9b189ff7d7d5ca4089 100644 (file)
@@ -1825,8 +1825,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
                }
        }
 
-#if IS_ENABLED(CONFIG_UNICODE)
-       if (!inode && IS_CASEFOLDED(dir)) {
+       if (IS_ENABLED(CONFIG_UNICODE) && !inode && IS_CASEFOLDED(dir)) {
                /* Eventually we want to call d_add_ci(dentry, NULL)
                 * for negative dentries in the encoding case as
                 * well.  For now, prevent the negative dentry
@@ -1834,7 +1833,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
                 */
                return NULL;
        }
-#endif
+
        return d_splice_alias(inode, dentry);
 }
 
@@ -3164,16 +3163,14 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
        ext4_fc_track_unlink(handle, dentry);
        retval = ext4_mark_inode_dirty(handle, dir);
 
-#if IS_ENABLED(CONFIG_UNICODE)
        /* VFS negative dentries are incompatible with Encoding and
         * Case-insensitiveness. Eventually we'll want avoid
         * invalidating the dentries here, alongside with returning the
         * negative dentries at ext4_lookup(), when it is better
         * supported by the VFS for the CI case.
         */
-       if (IS_CASEFOLDED(dir))
+       if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
                d_invalidate(dentry);
-#endif
 
 end_rmdir:
        brelse(bh);
@@ -3275,16 +3272,15 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
                goto out_trace;
 
        retval = __ext4_unlink(dir, &dentry->d_name, d_inode(dentry), dentry);
-#if IS_ENABLED(CONFIG_UNICODE)
+
        /* VFS negative dentries are incompatible with Encoding and
         * Case-insensitiveness. Eventually we'll want avoid
         * invalidating the dentries here, alongside with returning the
         * negative dentries at ext4_lookup(), when it is  better
         * supported by the VFS for the CI case.
         */
-       if (IS_CASEFOLDED(dir))
+       if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
                d_invalidate(dentry);
-#endif
 
 out_trace:
        trace_ext4_unlink_exit(dentry, retval);
index c682fb927b64b8a0fba027f32c27c968cbb8ed93..d2d2254a9dedb7a4d2913b13697ea9fece3b9840 100644 (file)
@@ -3586,14 +3586,12 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)
                return 0;
        }
 
-#if !IS_ENABLED(CONFIG_UNICODE)
-       if (ext4_has_feature_casefold(sb)) {
+       if (!IS_ENABLED(CONFIG_UNICODE) && ext4_has_feature_casefold(sb)) {
                ext4_msg(sb, KERN_ERR,
                         "Filesystem with casefold feature cannot be "
                         "mounted without CONFIG_UNICODE");
                return 0;
        }
-#endif
 
        if (readonly)
                return 1;