On Wed, Jul 08, 2020 at 07:44:28AM +0000, Avri Altman wrote: > > + > > +static enum blk_crypto_mode_num > > +ufshcd_find_blk_crypto_mode(union ufs_crypto_cap_entry cap) > > +{ > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(ufs_crypto_algs); i++) { > > + BUILD_BUG_ON(UFS_CRYPTO_KEY_SIZE_INVALID != 0); > > + if (ufs_crypto_algs[i].ufs_alg == cap.algorithm_id && > > + ufs_crypto_algs[i].ufs_key_size == cap.key_size) { > > + return i; > > + } > > + } > > + return BLK_ENCRYPTION_MODE_INVALID; > BLK_ENCRYPTION_MODE_INVALID is 0, but 0 is a valid mode num? ufs_crypto_algs[] does have to contain an entry for BLK_ENCRYPTION_MODE_INVALID, but it's an empty entry with ufs_key_size == UFS_CRYPTO_KEY_SIZE_INVALID (0). So it will never be selected and the code is correct. We should probably start iterating at 1 to make this clearer, though note that the code still needs to handle empty entries anyway in case any gaps are ever introduced into the BLK_ENCRYPTION_MODE_* values. - Eric