lkml.org 
[lkml]   [2022]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Weird code with change "mm/gup: clean up follow_pfn_pte() slightly"
From
On 2/2/22 22:27, Lukas Bulwahn wrote:
> Dear John,
>
> Your change "mm/gup: clean up follow_pfn_pte() slightly" (see Link),
> visible in linux-next as commit 05fef840b5c6 ("mm/gup: clean up
> follow_pfn_pte() slightly"), is somehow weird.

Well. That sounds like something to be avoided. :)

>
> In the new branch if (pages), you set page = ERR_PTR(-EFAULT) and goto
> out. However, at the label out, the value of page is not used, but the
> return uses the variables i and ret.

Yes, I think that the complaint is accurate. The intent of this code is
to return either number of pages so far (i) or ret (which should be zero
in this case), because we are just stopping early, rather than calling
this an actual error.

And since we do skip over setting pages[i] = pages, it's pointless to
assign page to anything.

So instead of this:

if (pages) {
page = ERR_PTR(-EFAULT);
goto out;
}

...I should have written this:

if (pages)
goto out;


I'll send an updated series with this correction.

Thank you for the report!


thanks,
--
John Hubbard
NVIDIA
>
> Static analysis tools, such as clang-analyzer, rightfully complain
> about such weird code.
>
> Maybe you can have another look at what you intended to set in the
> branch of that commit or if you intend to jump to the label out?
>
>
> Best regards,
>
> Lukas
>
> Link: https://lkml.kernel.org/r/20220201101108.306062-3-jhubbard@nvidia.com

\
 
 \ /
  Last update: 2022-02-03 09:39    [W:0.079 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site