From: David Ahern <dsahern@gmail.com>
To: zhang kai <zhangkaiheb@126.com>, davem@davemloft.net
Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ipv4: only allow increasing fib_info_hash_size
Date: Tue, 12 Oct 2021 07:55:24 -0600 [thread overview]
Message-ID: <23911752-3971-0230-cfd2-f8e30e8805db@gmail.com> (raw)
In-Reply-To: <20211012110658.10166-1-zhangkaiheb@126.com>
On 10/12/21 5:06 AM, zhang kai wrote:
> and when failed to allocate memory, check fib_info_hash_size.
what problem are you trying to solve?
>
> Signed-off-by: zhang kai <zhangkaiheb@126.com>
> ---
> net/ipv4/fib_semantics.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
> index a632b66bc..7547708a9 100644
> --- a/net/ipv4/fib_semantics.c
> +++ b/net/ipv4/fib_semantics.c
> @@ -1403,17 +1403,20 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
>
> if (!new_size)
> new_size = 16;
> - bytes = new_size * sizeof(struct hlist_head *);
> - new_info_hash = fib_info_hash_alloc(bytes);
> - new_laddrhash = fib_info_hash_alloc(bytes);
> - if (!new_info_hash || !new_laddrhash) {
> - fib_info_hash_free(new_info_hash, bytes);
> - fib_info_hash_free(new_laddrhash, bytes);
> - } else
> - fib_info_hash_move(new_info_hash, new_laddrhash, new_size);
> -
> - if (!fib_info_hash_size)
> - goto failure;
> +
> + if (new_size > fib_info_hash_size) {
> + bytes = new_size * sizeof(struct hlist_head *);
> + new_info_hash = fib_info_hash_alloc(bytes);
> + new_laddrhash = fib_info_hash_alloc(bytes);
> + if (!new_info_hash || !new_laddrhash) {
> + fib_info_hash_free(new_info_hash, bytes);
> + fib_info_hash_free(new_laddrhash, bytes);
> +
> + if (!fib_info_hash_size)
> + goto failure;
> + } else
> + fib_info_hash_move(new_info_hash, new_laddrhash, new_size);
> + }
> }
>
> fi = kzalloc(struct_size(fi, fib_nh, nhs), GFP_KERNEL);
>
next prev parent reply other threads:[~2021-10-12 13:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 11:06 [PATCH] ipv4: only allow increasing fib_info_hash_size zhang kai
2021-10-12 13:55 ` David Ahern [this message]
[not found] ` <3bd88b51.6c7.17c77339c10.Coremail.zhangkaiheb@126.com>
2021-10-13 2:33 ` David Ahern
[not found] ` <5219d023.14d1.17c778a9a18.Coremail.zhangkaiheb@126.com>
[not found] ` <1e3f52c3.350f.17c78afcc56.Coremail.zhangkaiheb@126.com>
2021-10-14 2:51 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23911752-3971-0230-cfd2-f8e30e8805db@gmail.com \
--to=dsahern@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
--cc=zhangkaiheb@126.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).