Message ID | 20210325212609.492188-2-satyat@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ensure bios aren't split in middle of crypto data unit | expand |
On Thu, Mar 25, 2021 at 09:26:02PM +0000, Satya Tangirala wrote: > This function checks if a given keyslot manager supports any encryption > mode/data unit size combination (and returns true if there is no such > supported combination). Helps clean up code a little. The name sounds a little strange to me, but the functionality looks ok. A kerneldoc comment might be useful to describe what it does so that we don't have to rely on the name alone.
On Thu, Mar 25, 2021 at 09:26:02PM +0000, Satya Tangirala wrote: > This function checks if a given keyslot manager supports any encryption > mode/data unit size combination (and returns true if there is no such > supported combination). Helps clean up code a little. > > Signed-off-by: Satya Tangirala <satyat@google.com> > --- > block/keyslot-manager.c | 13 +++++++++++++ > drivers/md/dm-table.c | 11 +---------- > include/linux/keyslot-manager.h | 2 ++ > 3 files changed, 16 insertions(+), 10 deletions(-) > > diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c > index 2c4a55bea6ca..2a2b1a9785d2 100644 > --- a/block/keyslot-manager.c > +++ b/block/keyslot-manager.c > @@ -437,6 +437,19 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm) > } > EXPORT_SYMBOL_GPL(blk_ksm_destroy); > > +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm) > +{ I agree with Christoph that this could use a kerneldoc comment. > diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h > index a27605e2f826..5bf0cea20c81 100644 > --- a/include/linux/keyslot-manager.h > +++ b/include/linux/keyslot-manager.h > @@ -117,4 +117,6 @@ bool blk_ksm_is_superset(struct blk_keyslot_manager *ksm_superset, > void blk_ksm_update_capabilities(struct blk_keyslot_manager *target_ksm, > struct blk_keyslot_manager *reference_ksm); > > +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm); > + It's easier to read if declarations are kept in the same order as the definitions. - Eric
diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 2c4a55bea6ca..2a2b1a9785d2 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -437,6 +437,19 @@ void blk_ksm_destroy(struct blk_keyslot_manager *ksm) } EXPORT_SYMBOL_GPL(blk_ksm_destroy); +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) { + if (ksm->crypto_modes_supported[i]) + return false; + } + + return true; +} +EXPORT_SYMBOL_GPL(blk_ksm_is_empty); + bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q) { if (blk_integrity_queue_supports_integrity(q)) { diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 95391f78b8d5..db18a58adad7 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1313,7 +1313,6 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t) struct blk_keyslot_manager *ksm; struct dm_target *ti; unsigned int i; - bool ksm_is_empty = true; dksm = kmalloc(sizeof(*dksm), GFP_KERNEL); if (!dksm) @@ -1350,15 +1349,7 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t) * If the new KSM doesn't actually support any crypto modes, we may as * well represent it with a NULL ksm. */ - ksm_is_empty = true; - for (i = 0; i < ARRAY_SIZE(ksm->crypto_modes_supported); i++) { - if (ksm->crypto_modes_supported[i]) { - ksm_is_empty = false; - break; - } - } - - if (ksm_is_empty) { + if (blk_ksm_is_empty(ksm)) { dm_destroy_keyslot_manager(ksm); ksm = NULL; } diff --git a/include/linux/keyslot-manager.h b/include/linux/keyslot-manager.h index a27605e2f826..5bf0cea20c81 100644 --- a/include/linux/keyslot-manager.h +++ b/include/linux/keyslot-manager.h @@ -117,4 +117,6 @@ bool blk_ksm_is_superset(struct blk_keyslot_manager *ksm_superset, void blk_ksm_update_capabilities(struct blk_keyslot_manager *target_ksm, struct blk_keyslot_manager *reference_ksm); +bool blk_ksm_is_empty(struct blk_keyslot_manager *ksm); + #endif /* __LINUX_KEYSLOT_MANAGER_H */
This function checks if a given keyslot manager supports any encryption mode/data unit size combination (and returns true if there is no such supported combination). Helps clean up code a little. Signed-off-by: Satya Tangirala <satyat@google.com> --- block/keyslot-manager.c | 13 +++++++++++++ drivers/md/dm-table.c | 11 +---------- include/linux/keyslot-manager.h | 2 ++ 3 files changed, 16 insertions(+), 10 deletions(-)