Re: [PATCH] x86/mtrr: Remove unnecessary strlen() in mtrr_write()
From: Ingo Molnar
Date: Tue Feb 25 2025 - 14:51:46 EST
* Thorsten Blum <thorsten.blum@xxxxxxxxx> wrote:
> On 25. Feb 2025, at 14:35, Ingo Molnar wrote:
> > * Thorsten Blum <thorsten.blum@xxxxxxxxx> 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@xxxxxxxxx>
> >> ---
> >
> > 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