lkml.org 
[lkml]   [2009]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm: __nr_to_section - make it safe against overflow
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];
> }


\
 
 \ /
  Last update: 2009-01-05 11:03    [W:0.063 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site