On Thu, 20 Dec 2018, Nicholas Mc Guire wrote:

> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 871e41c..1c118d7 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1258,7 +1258,7 @@ void __init vmalloc_init(void)
>  
>       /* Import existing vmlist entries. */
>       for (tmp = vmlist; tmp; tmp = tmp->next) {
> -             va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
> +             va = kzalloc(sizeof(*va), GFP_NOWAIT | __GFP_NOFAIL);
>               va->flags = VM_VM_AREA;
>               va->va_start = (unsigned long)tmp->addr;
>               va->va_end = va->va_start + tmp->size;

Hi Nicholas,

You're right that this looks wrong because there's no guarantee that va is 
actually non-NULL.  __GFP_NOFAIL won't help in init, unfortunately, since 
we're not giving the page allocator a chance to reclaim so this would 
likely just end up looping forever instead of crashing with a NULL pointer 
dereference, which would actually be the better result.

You could do

        BUG_ON(!va);

to make it obvious why we crashed, however.  It makes it obvious that the 
crash is intentional rather than some error in the kernel code.

Reply via email to