On 10/12/21 7:10 PM, 张凯 wrote:
>
> 1) Below shift operation will set fib_info_hash_size to zero if there
> are so many routes:
> unsigned int new_size = fib_info_hash_size << 1;
>
> This will wrap value of fib_info_hash_size, and a lot of fib_info
> will insert to a small hash bucket.
> so this patch disables above wrap.
> 2) Check whether fib_info_hash_size is zero only needed after allocation
> failed:
> if (!new_info_hash || !new_laddrhash) {
>
>
why not something simpler like this:
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 3364cb9c67e0..5c4bd1cebe0a 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1401,6 +1401,10 @@ struct fib_info *fib_create_info(struct
fib_config *cfg,
if (!new_size)
new_size = 16;
+
+ if (new_size < fib_info_hash_size)
+ goto failure;
+
bytes = new_size * sizeof(struct hlist_head *);
new_info_hash = fib_info_hash_alloc(bytes);
new_laddrhash = fib_info_hash_alloc(bytes);