All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Muchun Song <songmuchun@bytedance.com>
Cc: peterz@infradead.org, tglx@linutronix.de, bigeasy@linutronix.de,
	namit@vmware.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] smp: Fix a potential usage of stale nr_cpus
Date: Mon, 27 Jul 2020 13:43:03 +0200	[thread overview]
Message-ID: <20200727114303.GA57241@gmail.com> (raw)
In-Reply-To: <20200721034239.72013-1-songmuchun@bytedance.com>


* Muchun Song <songmuchun@bytedance.com> wrote:

> When the cmdline of "nr_cpus" is not valid, the @nr_cpu_ids is assigned
> a stale value. The nr_cpus is only valid when get_option() return 1. So
> check the return value to prevent this.
> 
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> changelog in v3:
>  1) Return -EINVAL when the parameter is bogus. 
> 
> changelog in v2:
>  1) Rework the commit log.
>  2) Rework the return value check.
> 
>  kernel/smp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/smp.c b/kernel/smp.c
> index a5a66fc28f4e..0dacfcfcf00b 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -772,9 +772,13 @@ static int __init nrcpus(char *str)
>  {
>  	int nr_cpus;
>  
> -	get_option(&str, &nr_cpus);
> +	if (get_option(&str, &nr_cpus) != 1)
> +		return -EINVAL;
> +
>  	if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
>  		nr_cpu_ids = nr_cpus;
> +	else
> +		return -EINVAL;

Exactly what does 'not valid' mean, and why doesn't get_option() 
return -EINVAL in that case?

Thanks,

	Ingo

  reply	other threads:[~2020-07-27 11:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21  3:42 [PATCH v3] smp: Fix a potential usage of stale nr_cpus Muchun Song
2020-07-27 11:43 ` Ingo Molnar [this message]
2020-07-27 16:04   ` Thomas Gleixner
2020-07-27 21:34     ` Ingo Molnar

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=20200727114303.GA57241@gmail.com \
    --to=mingo@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namit@vmware.com \
    --cc=peterz@infradead.org \
    --cc=songmuchun@bytedance.com \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.