linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <jiangshanlai@gmail.com>
To: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Tejun Heo <tj@kernel.org>, linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] workqueue: Fix possible memory leaks in wq_numa_init()
Date: Mon, 19 Jul 2021 16:49:05 +0800	[thread overview]
Message-ID: <CAJhGHyC-PzzjSmtEnvOkXNJkn5p2oejk8ctyan3r5AxP-G+O-A@mail.gmail.com> (raw)
In-Reply-To: <20210719065914.3801-1-thunder.leizhen@huawei.com>

Hello, Tejun

I think it would be better to fix it.
There have been several tries, sorted by date:

https://lore.kernel.org/lkml/1418379595-6281-2-git-send-email-laijs@cn.fujitsu.com/
https://lore.kernel.org/lkml/1442457835-24238-1-git-send-email-xlpang@126.com/
https://lore.kernel.org/lkml/1452170339-26748-3-git-send-email-wanghaibin.wang@huawei.com/
https://lore.kernel.org/lkml/1533518439-3982-1-git-send-email-wang.yi59@zte.com.cn/

And this one.

Thanks
Lai


On Mon, Jul 19, 2021 at 3:00 PM Zhen Lei <thunder.leizhen@huawei.com> wrote:
>
> In error handling branch "if (WARN_ON(node == NUMA_NO_NODE))", the
> previously allocated memories are not released. Doing this before
> allocating memory eliminates memory leaks.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  kernel/workqueue.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 50142fc08902..6aa0ba582d15 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -5896,6 +5896,14 @@ static void __init wq_numa_init(void)
>                 return;
>         }
>
> +       for_each_possible_cpu(cpu) {
> +               if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) {
> +                       pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
> +                       /* happens iff arch is bonkers, let's just proceed */
> +                       return;
> +               }
> +       }
> +
>         wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs();
>         BUG_ON(!wq_update_unbound_numa_attrs_buf);
>
> @@ -5907,18 +5915,11 @@ static void __init wq_numa_init(void)
>         tbl = kcalloc(nr_node_ids, sizeof(tbl[0]), GFP_KERNEL);
>         BUG_ON(!tbl);
>
> -       for_each_node(node)
> +       for_each_node(node) {
>                 BUG_ON(!zalloc_cpumask_var_node(&tbl[node], GFP_KERNEL,
>                                 node_online(node) ? node : NUMA_NO_NODE));
>
> -       for_each_possible_cpu(cpu) {
> -               node = cpu_to_node(cpu);
> -               if (WARN_ON(node == NUMA_NO_NODE)) {
> -                       pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
> -                       /* happens iff arch is bonkers, let's just proceed */
> -                       return;
> -               }
> -               cpumask_set_cpu(cpu, tbl[node]);
> +               cpumask_copy(tbl[node], cpumask_of_node(node));
>         }
>
>         wq_numa_possible_cpumask = tbl;
> --
> 2.25.1
>

  reply	other threads:[~2021-07-19  8:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  6:59 Zhen Lei
2021-07-19  8:49 ` Lai Jiangshan [this message]
2021-07-21 16:23   ` Tejun Heo
2021-07-22  1:55 ` Lai Jiangshan
2021-07-22  2:37   ` Leizhen (ThunderTown)
2021-07-22  2:05 ` Lai Jiangshan
2021-07-22  2:44   ` Leizhen (ThunderTown)

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=CAJhGHyC-PzzjSmtEnvOkXNJkn5p2oejk8ctyan3r5AxP-G+O-A@mail.gmail.com \
    --to=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thunder.leizhen@huawei.com \
    --cc=tj@kernel.org \
    --subject='Re: [PATCH] workqueue: Fix possible memory leaks in wq_numa_init()' \
    /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

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).