]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: ufs: crypto: Add ufs_hba_from_crypto_profile()
authorEric Biggers <ebiggers@google.com>
Fri, 13 Dec 2024 04:19:45 +0000 (20:19 -0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 2 Jan 2025 18:36:15 +0000 (13:36 -0500)
Add a helper function that encapsulates a container_of expression.  For now
there are two users but soon there will be more.

Tested-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> # sm8650
Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://lore.kernel.org/r/20241213041958.202565-3-ebiggers@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ufs/core/ufshcd-crypto.c
include/ufs/ufshcd.h

index a714dad82cd1feff4984c25ed408de4b6946f187..0cb425ef618e89f72f924594f7e46d3f1d73c6cd 100644 (file)
@@ -52,8 +52,7 @@ static int ufshcd_crypto_keyslot_program(struct blk_crypto_profile *profile,
                                         const struct blk_crypto_key *key,
                                         unsigned int slot)
 {
-       struct ufs_hba *hba =
-               container_of(profile, struct ufs_hba, crypto_profile);
+       struct ufs_hba *hba = ufs_hba_from_crypto_profile(profile);
        const union ufs_crypto_cap_entry *ccap_array = hba->crypto_cap_array;
        const struct ufs_crypto_alg_entry *alg =
                        &ufs_crypto_algs[key->crypto_cfg.crypto_mode];
@@ -99,8 +98,7 @@ static int ufshcd_crypto_keyslot_evict(struct blk_crypto_profile *profile,
                                       const struct blk_crypto_key *key,
                                       unsigned int slot)
 {
-       struct ufs_hba *hba =
-               container_of(profile, struct ufs_hba, crypto_profile);
+       struct ufs_hba *hba = ufs_hba_from_crypto_profile(profile);
        /*
         * Clear the crypto cfg on the device. Clearing CFGE
         * might not be sufficient, so just clear the entire cfg.
index ce7667b020e25fa3f8f30b3a603378315919755f..ec0cbffc44ced25cbb16f16cea355d966bb61b35 100644 (file)
@@ -1211,6 +1211,14 @@ static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
        ({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); })
 #endif
 
+#ifdef CONFIG_SCSI_UFS_CRYPTO
+static inline struct ufs_hba *
+ufs_hba_from_crypto_profile(struct blk_crypto_profile *profile)
+{
+       return container_of(profile, struct ufs_hba, crypto_profile);
+}
+#endif
+
 static inline size_t ufshcd_get_ucd_size(const struct ufs_hba *hba)
 {
        return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);