All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	linux-metag@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paul <Paul.Burton@imgtec.com>
Subject: Re: [PATCH] arch: metag: mm: hugetlbpage.c:  Cleaning up inconsistent NULL checks
Date: Wed, 28 May 2014 11:03:23 +0100	[thread overview]
Message-ID: <5385B46B.9030807@imgtec.com> (raw)
In-Reply-To: <1400796102-12832-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

Hi Rickard,

On 22/05/14 23:01, Rickard Strandqvist wrote:
> Cleaning up inconsistent NULL checks.
> There is otherwise a risk of a possible null pointer dereference.
> 
> Was largely found by using a static code analysis program called cppcheck.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  arch/metag/mm/hugetlbpage.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
> index 0424315..3f8d5cd 100644
> --- a/arch/metag/mm/hugetlbpage.c
> +++ b/arch/metag/mm/hugetlbpage.c
> @@ -188,7 +188,8 @@ new_search:
>  			}
>  		}
>  		after_huge = 0;
> -		addr = ALIGN_HUGEPT(vma->vm_end);
> +		if (vma)
> +			addr = ALIGN_HUGEPT(vma->vm_end);
>  	}
>  }
>  #endif
> 

I don't think this is a correct fix.

If !vma && !after_huge the first if block in the loop will match and the
function will return 0.
If !vma && after_huge the 3rd if block in the loop will match and the
function will return addr.

So removing the vma condition on the final if block in the loop would
probably make sense instead. Does that satisfy cppcheck?

Cheers
James

WARNING: multiple messages have this Message-ID (diff)
From: James Hogan <james.hogan@imgtec.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	<linux-metag@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Paul <Paul.Burton@imgtec.com>
Subject: Re: [PATCH] arch: metag: mm: hugetlbpage.c:  Cleaning up inconsistent NULL checks
Date: Wed, 28 May 2014 11:03:23 +0100	[thread overview]
Message-ID: <5385B46B.9030807@imgtec.com> (raw)
In-Reply-To: <1400796102-12832-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

Hi Rickard,

On 22/05/14 23:01, Rickard Strandqvist wrote:
> Cleaning up inconsistent NULL checks.
> There is otherwise a risk of a possible null pointer dereference.
> 
> Was largely found by using a static code analysis program called cppcheck.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  arch/metag/mm/hugetlbpage.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
> index 0424315..3f8d5cd 100644
> --- a/arch/metag/mm/hugetlbpage.c
> +++ b/arch/metag/mm/hugetlbpage.c
> @@ -188,7 +188,8 @@ new_search:
>  			}
>  		}
>  		after_huge = 0;
> -		addr = ALIGN_HUGEPT(vma->vm_end);
> +		if (vma)
> +			addr = ALIGN_HUGEPT(vma->vm_end);
>  	}
>  }
>  #endif
> 

I don't think this is a correct fix.

If !vma && !after_huge the first if block in the loop will match and the
function will return 0.
If !vma && after_huge the 3rd if block in the loop will match and the
function will return addr.

So removing the vma condition on the final if block in the loop would
probably make sense instead. Does that satisfy cppcheck?

Cheers
James

  reply	other threads:[~2014-05-28 10:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 22:01 [PATCH] arch: metag: mm: hugetlbpage.c: Cleaning up inconsistent NULL checks Rickard Strandqvist
2014-05-22 22:01 ` Rickard Strandqvist
2014-05-28 10:03 ` James Hogan [this message]
2014-05-28 10:03   ` James Hogan
2014-05-29 22:45   ` Rickard Strandqvist

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=5385B46B.9030807@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=Paul.Burton@imgtec.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-metag@vger.kernel.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=rickard_strandqvist@spectrumdigital.se \
    /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.