From: linlzhan <[email protected]>

ufshcd_prepare_lrbp_crypto() programs crypto_key_slot in the LRB from
rq->crypt_keyslot.  With the blk-crypto slot path a bio can carry a
pre-programmed physical ICE keyslot index in crypt_ctx->bc_slot rather
than a blk_crypto_key pointer.  In that case rq->crypt_keyslot is NULL
and the existing code incorrectly falls through to the "no encryption"
path, leaving crypto_key_slot as -1.

Extend the function to handle both cases: when rq->crypt_keyslot is
set, derive the slot index via blk_crypto_keyslot_index() as before;
when bc_slot.data_unit_size_bits is non-zero, read crypto_key_slot
directly from bc_slot.phy_slot.

Signed-off-by: linlzhan <[email protected]>
---
 drivers/ufs/core/ufshcd-crypto.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/ufs/core/ufshcd-crypto.h b/drivers/ufs/core/ufshcd-crypto.h
index 8f66db94e179..2fc5601c0f76 100644
--- a/drivers/ufs/core/ufshcd-crypto.h
+++ b/drivers/ufs/core/ufshcd-crypto.h
@@ -15,13 +15,21 @@
 static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
                                              struct ufshcd_lrb *lrbp)
 {
-       if (!rq || !rq->crypt_keyslot) {
+       if (!rq) {
                lrbp->crypto_key_slot = -1;
                return;
        }
 
-       lrbp->crypto_key_slot = blk_crypto_keyslot_index(rq->crypt_keyslot);
-       lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
+       if (rq->crypt_keyslot) {
+               lrbp->crypto_key_slot = 
blk_crypto_keyslot_index(rq->crypt_keyslot);
+               lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
+       } else if (rq->crypt_ctx && rq->crypt_ctx->bc_slot.data_unit_size_bits) 
{
+               lrbp->crypto_key_slot = rq->crypt_ctx->bc_slot.phy_slot;
+               lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
+       } else {
+               lrbp->crypto_key_slot = -1;
+       }
+
 }
 
 static inline void
-- 
2.34.1


Reply via email to