Commit 3ee9a4f0 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

mm: neaten warn_alloc_failed

Add __attribute__((format (printf...) to the function to validate format
and arguments.  Use vsprintf extension %pV to avoid any possible message
interleaving.  Coalesce format string.  Convert printks/pr_warning to
pr_warn.

[akpm@linux-foundation.org: use the __printf() macro]
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 06d5e032
...@@ -1334,7 +1334,8 @@ extern void si_meminfo(struct sysinfo * val); ...@@ -1334,7 +1334,8 @@ extern void si_meminfo(struct sysinfo * val);
extern void si_meminfo_node(struct sysinfo *val, int nid); extern void si_meminfo_node(struct sysinfo *val, int nid);
extern int after_bootmem; extern int after_bootmem;
extern void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...); extern __printf(3, 4)
void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
extern void setup_per_cpu_pageset(void); extern void setup_per_cpu_pageset(void);
......
...@@ -1754,7 +1754,6 @@ static DEFINE_RATELIMIT_STATE(nopage_rs, ...@@ -1754,7 +1754,6 @@ static DEFINE_RATELIMIT_STATE(nopage_rs,
void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...) void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
{ {
va_list args;
unsigned int filter = SHOW_MEM_FILTER_NODES; unsigned int filter = SHOW_MEM_FILTER_NODES;
if ((gfp_mask & __GFP_NOWARN) || !__ratelimit(&nopage_rs)) if ((gfp_mask & __GFP_NOWARN) || !__ratelimit(&nopage_rs))
...@@ -1773,14 +1772,21 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...) ...@@ -1773,14 +1772,21 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
filter &= ~SHOW_MEM_FILTER_NODES; filter &= ~SHOW_MEM_FILTER_NODES;
if (fmt) { if (fmt) {
printk(KERN_WARNING); struct va_format vaf;
va_list args;
va_start(args, fmt); va_start(args, fmt);
vprintk(fmt, args);
vaf.fmt = fmt;
vaf.va = &args;
pr_warn("%pV", &vaf);
va_end(args); va_end(args);
} }
pr_warning("%s: page allocation failure: order:%d, mode:0x%x\n", pr_warn("%s: page allocation failure: order:%d, mode:0x%x\n",
current->comm, order, gfp_mask); current->comm, order, gfp_mask);
dump_stack(); dump_stack();
if (!should_suppress_show_mem()) if (!should_suppress_show_mem())
......
...@@ -1593,8 +1593,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, ...@@ -1593,8 +1593,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
return area->addr; return area->addr;
fail: fail:
warn_alloc_failed(gfp_mask, order, "vmalloc: allocation failure, " warn_alloc_failed(gfp_mask, order,
"allocated %ld of %ld bytes\n", "vmalloc: allocation failure, allocated %ld of %ld bytes\n",
(area->nr_pages*PAGE_SIZE), area->size); (area->nr_pages*PAGE_SIZE), area->size);
vfree(area->addr); vfree(area->addr);
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment