public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mtrr: Remove unnecessary strlen() in mtrr_write()
Date: Tue, 25 Feb 2025 20:50:17 +0100	[thread overview]
Message-ID: <Z74e-ZHCu6cV4dfi@gmail.com> (raw)
In-Reply-To: <35EF1145-7214-4B51-8168-4D54028BE0E5@linux.dev>


* Thorsten Blum <thorsten.blum@linux.dev> wrote:

> On 25. Feb 2025, at 14:35, Ingo Molnar wrote:
> > * Thorsten Blum <thorsten.blum@linux.dev> wrote:
> > 
> >> The local variable length already holds the string length after calling
> >> strncpy_from_user(). Using another local variable linlen and calling
> >> strlen() is therefore unnecessary and can be removed. Remove linlen
> >> and strlen() and use length instead.
> >> 
> >> Compile-tested only.
> >> 
> >> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> >> ---
> > 
> > I see no corner-case analysis in the changelog about what may happen if 
> > the copy fails partially.
> 
> Hi Ingo,
> 
> I'm not sure what you mean. Why would I describe something I didn't
> change? This patch only removes an unnecessary string (line) length
> calculation and shouldn't affect the logic in any way.
> 
> If strncpy_from_user() fails, we immediately return length from
> mtrr_write(), but my patch doesn't change this - unless I'm missing
> something?

My bad: I was fixated on this 'some data may have been copied' language 
in the strncpy_from_user() documentation:

 * If access to userspace fails, returns -EFAULT (some data may have been
 * copied).

which would make the strlen() result ambiguous. But this doesn't matter 
here - if there was a fault then we get an unconditional -EFAULT from 
strncpy_from_user(), so your patch should be equivalent to the previous 
logic.

Thanks,

	Ingo

  reply	other threads:[~2025-02-25 19:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 13:16 [PATCH] x86/mtrr: Remove unnecessary strlen() in mtrr_write() Thorsten Blum
2025-02-25 13:35 ` Ingo Molnar
2025-02-25 19:17   ` Thorsten Blum
2025-02-25 19:50     ` Ingo Molnar [this message]
2025-02-25 20:00 ` [tip: x86/mm] " tip-bot2 for Thorsten Blum

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=Z74e-ZHCu6cV4dfi@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thorsten.blum@linux.dev \
    --cc=x86@kernel.org \
    /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