Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7248739rwn; Tue, 13 Sep 2022 17:02:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR5oK1ZI6OrgVIrjLi5DFu5i4X7RseS4qlnCVsTqjDIxGNcDr7hGGMu6JQ4/clpbKT3lBCsF X-Received: by 2002:aa7:88c9:0:b0:541:2b7:d655 with SMTP id k9-20020aa788c9000000b0054102b7d655mr22139936pff.72.1663113766715; Tue, 13 Sep 2022 17:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663113766; cv=none; d=google.com; s=arc-20160816; b=KQZmGIU05I/7VyksILyOKqIAQXZ/CG5aVpW0Jc81X0b3vBK55l2adEOuNwu2NTn+f2 K53H1DxZEOQVHxBg7jK+nYPpQkmdsuxlNOn7kRyDlUJyUfghI2tnprRsVGG/4llK1t6E 857ghAYbaAywcdeXINthifvwyciQsdkWK8MDx71XjYbRhntKAwLYQM+mExGm/f+8InvR pXaotGXJx8Q4YUPg+AGv3JYn/nEBtsLoiXxnTzSszOUb9DeurDLeqRiVhgcPjd1Jpia3 rjdtoX70tdj/Y15QNP8ZbyjdIKc7UKz4pt8l0QtiqJ0PPyGYbYXRehqJhmtllZZ1u442 azCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dW2wCaqcIDGiGOwrIxRGUl6eaX/RTAiDxiuyhdioejQ=; b=IoQIgm41JC91TqJ/eT3cUnv/kFALe84PY+Hzo31ickKGrtX3CVcQztcGScC+yg7kOd z2Wvquai6YVDPOzndM8EghGRC3slFq4aOL4mVvVJTwSW7O32L25m0YeWPBaG5Rh0TKJa f9XE+Qm7nAAOljc/1xoobhmHMuVn8e/Mu2P7dcU64N1OZAI3adxrYpywS+w027FwskNB gVHp/6YCTCJ1/75QeWXODVgZph7S8+6F3Cx+D2BUPOup2uDB3gjTeyNP9xWiLqWEhsPn GDHV1pmrPINTvbvgb+gxdaCvDIqyHLme4SWlGx+jWQ9j4hQi52UE8yZC4sb5t1BcjbDZ GRPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VzwXBSiN; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a634704000000b00434c04c7bd0si13227978pga.306.2022.09.13.17.02.31; Tue, 13 Sep 2022 17:02:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VzwXBSiN; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbiIMXmc (ORCPT + 99 others); Tue, 13 Sep 2022 19:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbiIMXma (ORCPT ); Tue, 13 Sep 2022 19:42:30 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0AB44551 for ; Tue, 13 Sep 2022 16:42:28 -0700 (PDT) Received: from localhost (modemcable141.102-20-96.mc.videotron.ca [96.20.102.141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: krisman) by madras.collabora.co.uk (Postfix) with ESMTPSA id 56A71660202D; Wed, 14 Sep 2022 00:42:27 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663112547; bh=a33LMC7xxApIQS2vau/J9KxbbG+qcYU2mrhACXJxisg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VzwXBSiNN+zYMTtwTysycDDzOhH1BBsvSRA/aeR937W3n1UU+6ndHVaIzVxufhNdC 6ZYfb3D2auU11w0z2mkFIb1VUtR7gFQ3dJkL5Ntqr/uiXUdur6oCu4yg2bya5YdTCj g1T0hrP0WDdBBXVxFO9I1CfcAcxUzu/DO+32NxnqoySZ9opIgGHWMwZbjg7WHBStf0 CktS7yznxCJ3h6aWsmVbtd5lUzh8Rq16F9jUG1+Ky8vKvd2FYtkCjqK9s3o0kWd2ET dsxUxBWk+A4dppPMrFTpi0n3QJsABPCCm0qi0/R+/ykz2+Ds0CiDDdmSMHe0qzbqwJ FzpDfyXTimG7g== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, ebiggers@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Gabriel Krisman Bertazi , kernel@collabora.com, Eric Biggers Subject: [PATCH v9 7/8] ext4: Move CONFIG_UNICODE defguards into the code flow Date: Tue, 13 Sep 2022 19:41:49 -0400 Message-Id: <20220913234150.513075-8-krisman@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913234150.513075-1-krisman@collabora.com> References: <20220913234150.513075-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Instead of a bunch of ifdefs, make the unicode built checks part of the code flow where possible, as requested by Torvalds. Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi --- Changes since v8: - Rebase on top of 3030b59c8533 ("ext4: cleanup function defs from ext4.h into crypto.c") Changes since v5: - Drop err variable (eric) Changes since v4: - Create stub for !CONFIG_UNICODE case (eric) --- fs/ext4/crypto.c | 15 +++------------ fs/ext4/ext4.h | 32 ++++++++++++++++++++------------ fs/ext4/namei.c | 15 ++++++--------- fs/ext4/super.c | 4 +--- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index e20ac0654b3f..c65d8a5f8315 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -31,10 +31,7 @@ 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); -#endif - return err; + return ext4_fname_setup_ci_filename(dir, iname, fname); } int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, @@ -49,10 +46,7 @@ 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); -#endif - return err; + return ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); } void ext4_fname_free_filename(struct ext4_filename *fname) @@ -66,10 +60,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]) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9717b9832425..f2a673ac67fe 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2734,8 +2734,24 @@ 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 */ @@ -2758,16 +2774,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, @@ -2779,10 +2790,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, diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 959346950b3c..100715586473 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1811,8 +1811,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 @@ -1820,7 +1819,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi */ return NULL; } -#endif + return d_splice_alias(inode, dentry); } @@ -3138,16 +3137,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); @@ -3243,16 +3240,16 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) retval = __ext4_unlink(handle, dir, &dentry->d_name, d_inode(dentry)); if (!retval) ext4_fc_track_unlink(handle, 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 + if (handle) ext4_journal_stop(handle); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9a66abcca1a8..6c8f5fa5e455 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3569,14 +3569,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; -- 2.37.3