mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Pekka Enberg" <penberg@cs.helsinki.fi>
To: "Cyrill Gorcunov" <gorcunov@gmail.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Nick Piggin" <npiggin@suse.de>, "Rik van Riel" <riel@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"Jiri Slaby" <jirislaby@gmail.com>
Subject: Re: [PATCH] mm: __nr_to_section - make it safe against overflow
Date: Mon, 5 Jan 2009 12:00:58 +0200	[thread overview]
Message-ID: <84144f020901050200h3fd6ce71qacd5e2dff282a9@mail.gmail.com> (raw)
In-Reply-To: <20090105094034.GA7645@localhost>

Hi Cyrill,

On Mon, Jan 5, 2009 at 11:40 AM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> @@ -980,9 +986,12 @@ extern struct mem_section mem_section[NR
>
>  static inline struct mem_section *__nr_to_section(unsigned long nr)
>  {
> -       if (!mem_section[SECTION_NR_TO_ROOT(nr)])
> +       unsigned long idx = SECTION_NR_TO_ROOT(nr);
> +       WARN_ON_ONCE(idx >= NR_SECTION_ROOTS);
> +
> +       if (idx >=NR_SECTION_ROOTS || !mem_section[idx])
>                return NULL;

Looks good to me but I have minor nitpick. You might want to write the
above like this:

    if (WARN_ON_ONCE(idx >= NR_SECTION_ROOTS))
            return NULL;

to separate the error condition from the normal case where we don't
have a mem section.

> -       return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
> +       return &mem_section[idx][nr & SECTION_ROOT_MASK];
>  }

  reply	other threads:[~2009-01-05 10:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-05  9:40 Cyrill Gorcunov
2009-01-05 10:00 ` Pekka Enberg [this message]
2009-01-05 10:03   ` Cyrill Gorcunov
2009-01-05 10:01 ` Cyrill Gorcunov
2009-01-05 15:10 ` Christoph Lameter
2009-01-05 15:28   ` Cyrill Gorcunov
2009-01-05 15:34     ` Nick Piggin
2009-01-05 16:12       ` Cyrill Gorcunov
2009-01-05 15:37     ` Christoph Lameter

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=84144f020901050200h3fd6ce71qacd5e2dff282a9@mail.gmail.com \
    --to=penberg@cs.helsinki.fi \
    --cc=akpm@linux-foundation.org \
    --cc=gorcunov@gmail.com \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npiggin@suse.de \
    --cc=riel@redhat.com \
    /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

all inboxes | Powered by JetHome®