From 62eaff4a16dd459a9fd60c3002738d7d06417eee Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 22 Nov 2024 00:02:26 +0100 Subject: [PATCH] libkmod: hash_new(): always use a step size of at least 4 The current algorithm would choose a step size of 4 for n_buckets == 31, but 1 for n_buckets == 32, which seems wrong. Fix it. Signed-off-by: Martin Wilck Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/257 Signed-off-by: Lucas De Marchi --- shared/hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/hash.c b/shared/hash.c index f9a0c00c..d0e7f86d 100644 --- a/shared/hash.c +++ b/shared/hash.c @@ -41,7 +41,7 @@ struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value)) hash->n_buckets = n_buckets; hash->free_value = free_value; hash->step = n_buckets / 32; - if (hash->step == 0) + if (hash->step < 4) hash->step = 4; else if (hash->step > 64) hash->step = 64; -- 2.47.2