Merge tag 'tif-task_work.arch-2020-12-14' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / block / keyslot-manager.c
index 35abcb1..86f8195 100644 (file)
@@ -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]),