diff options
author | Linus Torvalds | 2020-11-27 12:49:01 -0800 |
---|---|---|
committer | Linus Torvalds | 2020-11-27 12:49:01 -0800 |
commit | d021c3e56d48b0a435eab3b3ec99d4e8bf8df2d1 (patch) | |
tree | c1921a059684301ca10098e1bbe6fff0bbbf1557 | |
parent | a17a3ca55e96d20e25e8b1a7cd08192ce2bac3cc (diff) | |
parent | 47a846536e1bf62626f1c0d8488f3718ce5f8296 (diff) |
Merge tag 'block-5.10-2020-11-27' of git://git.kernel.dk/linux-block
Pull block fix from Jens Axboe:
"Just a single fix, for a crash in the keyslot manager"
* tag 'block-5.10-2020-11-27' of git://git.kernel.dk/linux-block:
block/keyslot-manager: prevent crash when num_slots=1
-rw-r--r-- | block/keyslot-manager.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c index 35abcb1ec051..86f8195d8039 100644 --- a/block/keyslot-manager.c +++ b/block/keyslot-manager.c @@ -103,6 +103,13 @@ int blk_ksm_init(struct blk_keyslot_manager *ksm, unsigned int num_slots) spin_lock_init(&ksm->idle_slots_lock); slot_hashtable_size = roundup_pow_of_two(num_slots); + /* + * hash_ptr() assumes bits != 0, so ensure the hash table has at least 2 + * buckets. This only makes a difference when there is only 1 keyslot. + */ + if (slot_hashtable_size < 2) + slot_hashtable_size = 2; + ksm->log_slot_ht_size = ilog2(slot_hashtable_size); ksm->slot_hashtable = kvmalloc_array(slot_hashtable_size, sizeof(ksm->slot_hashtable[0]), |