projects/linux·commit d021c3e5

Merge tag 'block-5.10-2020-11-27' of git://git.kernel.dk/linux-block

d021c3e5 · Linus Torvalds <[email protected]> · 2020-11-27 12:49:01 -08:00

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
Commit
d021c3e56d48b0a435eab3b3ec99d4e8bf8df2d1
Parents
a17a3ca5 · 47a84653

Merge commit. Changes below are compared with the first parent: a17a3ca5.

Changes

1 files changed · +7 −0

FileStatusAddDelContent
block/keyslot-manager.cmodified+7−0View file

block/keyslot-manager.c

View file
diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c
index 35abcb1..86f8195 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]),