]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: hash_new(): always use a step size of at least 4
authorMartin Wilck <mwilck@suse.com>
Thu, 21 Nov 2024 23:02:26 +0000 (00:02 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 29 Nov 2024 15:15:21 +0000 (09:15 -0600)
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 <mwilck@suse.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/257
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/hash.c

index f9a0c00cfec405b60cadbbc6a220c8729ab7e96b..d0e7f86d727166437a27a9ee79cbc8a5f7d847cd 100644 (file)
@@ -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;