Limit range of __init_ref_ok somewhat
PATCH 1/1 Limit range of __init_ref_ok somewhat
This patch introduces zalloc_maybe_bootmem and uses it so that we don;t have to mark a whole (largish) routine as __init_ref_ok.
--- arch/powerpc/kernel/irq.c | 10 ++-------- arch/powerpc/lib/alloc.c | 15 +++++++++++++++ include/asm-powerpc/system.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-)
Signature · 2 lines
Cheers, Stephen Rothwell [email protected]
arch/powerpc/kernel/irq.c +2 -8
@@ -424,7 +424,7 @@ static int default_irq_host_match(struct irq_host *h, struct device_node *np)return h->of_node !=NULL && h->of_node == np; } -__init_refok struct irq_host *irq_alloc_host(struct device_node *of_node, +struct irq_host *irq_alloc_host(struct device_node *of_node, unsigned int revmap_type, unsigned int revmap_arg, struct irq_host_ops *ops,
@@ -439,13 +439,7 @@ __init_refok struct irq_host *irq_alloc_host(struct device_node *of_node,/* Allocate structure and revmap table if using linear mapping */ if (revmap_type ==IRQ_HOST_MAP_LINEAR ) size += revmap_arg *sizeof (unsigned int ); -if (mem_init_done) - host =kzalloc (size,GFP_KERNEL ); -else { - host =alloc_bootmem (size); -if (host) -memset (host,0 , size); - } + host =zalloc_maybe_bootmem (size,GFP_KERNEL );if (host ==NULL )return NULL ;
arch/powerpc/lib/alloc.c +15 -0
@@ -2,6 +2,7 @@#include <linux/init.h> #include <linux/slab.h> #include <linux/bootmem.h> +#include <linux/string.h> #include <asm/system.h>
@@ -12,3 +13,17 @@ void * __init_refok alloc_maybe_bootmem(size_t size, gfp_t mask)else return alloc_bootmem (size); } + +void * __init_refok zalloc_maybe_bootmem(size_t size, gfp_t mask) +{ +void *p; + +if (mem_init_done) + p =kzalloc (size, mask); +else { + p =alloc_bootmem (size); +if (p) +memset (p,0 , size); + } +return p; +}
include/asm-powerpc/system.h +1 -0
@@ -190,6 +190,7 @@ extern unsigned long memory_limit;extern unsigned long klimit;extern void *alloc_maybe_bootmem (size_t size,gfp_t mask); +extern void *zalloc_maybe_bootmem (size_t size,gfp_t mask);extern int powersave_nap;/* set if nap mode can be used in idle loop */
Signature · 1 line
1.5.3.2
mem_init_done (was: Re: [PATCH] [POWERPC] Limit range of __init_ref_ok somewhat)
arch/powerpc/lib/alloc.c void * __init_refok alloc_maybe_bootmem(size_t size, gfp_t mask) · line 29
Quoted 13 lines · Stephen Rothwell
arch/powerpc/lib/alloc.c +13
-0+void * __init_refok zalloc_maybe_bootmem(size_t size, gfp_t mask) +{ +void *p; + +if (mem_init_done) + p =kzalloc (size, mask); +else { + p =alloc_bootmem (size); +if (p) +memset (p,0 , size); + } +return p; +}
BTW, is this `mem_init_done' flag the recommended(TM) way to handle this? Or is it just something that always stayed under the radar of the reviewers, as only PPC has it (and Atari)?
I remember we had something similar globally when __init was introduced, which was used by the frame buffer code to determine whether to draw the penguin logo (which is __initdata) or not. This code had to be ripped out (and was replaced by the FBINFO_MODULE logic), because people didn't like mem_init_done flags...
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453 Fax: +32 (0)2 700 8622 E-mail: [email protected] Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V. Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
PATCH 1/1 powerpc: another use of zalloc_maybe_bootmem()
In reply to Stephen RothwellUse alloc_maybe_bootmem() which wraps the if(mem_init_done) malloc clause.
----
Quoted 2 lines · Stephen Rothwell
This patch introduces
zalloc_maybe_bootmemand uses it so that we don;t have to mark a whole (largish) routine as__init_ref_ok.
sfr missed a spot -- may as well get rid of this one too.
arch/powerpc/kernel/pci-common.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/powerpc/kernel/pci-common.c +2 -5
@@ -65,14 +65,11 @@ static void __devinit pci_setup_pci_contspin_unlock (&hose_spinlock); } -__init_refok struct pci_controller * pcibios_alloc_controller(struct device_node *dev) +struct pci_controller *pcibios_alloc_controller (struct device_node *dev) {struct pci_controller *phb; -if (mem_init_done) - phb =kmalloc (sizeof (struct pci_controller ),GFP_KERNEL ); -else - phb =alloc_bootmem (sizeof (struct pci_controller )); + phb =alloc_maybe_bootmem (sizeof (struct pci_controller ),GFP_KERNEL );if (phb ==NULL )return NULL ;pci_setup_pci_controller (phb);