Skip to content

Commit 75d0c64

Browse files
ebiggersmartinkpetersen
authored andcommitted
scsi: ufs: crypto: Add ufs_hba_from_crypto_profile()
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 <[email protected]> # sm8650 Signed-off-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 7a0905c commit 75d0c64

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/ufs/core/ufshcd-crypto.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ static int ufshcd_crypto_keyslot_program(struct blk_crypto_profile *profile,
5252
const struct blk_crypto_key *key,
5353
unsigned int slot)
5454
{
55-
struct ufs_hba *hba =
56-
container_of(profile, struct ufs_hba, crypto_profile);
55+
struct ufs_hba *hba = ufs_hba_from_crypto_profile(profile);
5756
const union ufs_crypto_cap_entry *ccap_array = hba->crypto_cap_array;
5857
const struct ufs_crypto_alg_entry *alg =
5958
&ufs_crypto_algs[key->crypto_cfg.crypto_mode];
@@ -99,8 +98,7 @@ static int ufshcd_crypto_keyslot_evict(struct blk_crypto_profile *profile,
9998
const struct blk_crypto_key *key,
10099
unsigned int slot)
101100
{
102-
struct ufs_hba *hba =
103-
container_of(profile, struct ufs_hba, crypto_profile);
101+
struct ufs_hba *hba = ufs_hba_from_crypto_profile(profile);
104102
/*
105103
* Clear the crypto cfg on the device. Clearing CFGE
106104
* might not be sufficient, so just clear the entire cfg.

include/ufs/ufshcd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,14 @@ static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
12111211
({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); })
12121212
#endif
12131213

1214+
#ifdef CONFIG_SCSI_UFS_CRYPTO
1215+
static inline struct ufs_hba *
1216+
ufs_hba_from_crypto_profile(struct blk_crypto_profile *profile)
1217+
{
1218+
return container_of(profile, struct ufs_hba, crypto_profile);
1219+
}
1220+
#endif
1221+
12141222
static inline size_t ufshcd_get_ucd_size(const struct ufs_hba *hba)
12151223
{
12161224
return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);

0 commit comments

Comments
 (0)