Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: acpi_os_allocate() fixes

Replace acpi_in_resume with a more general hack
to check irqs_disabled() on any kmalloc() from ACPI.
While setting (system_state != SYSTEM_RUNNING) on resume
seemed more general, Andrew Morton preferred this approach.

http://bugzilla.kernel.org/show_bug.cgi?id=3469

Make acpi_os_allocate() into an inline function to
allow /proc/slab_allocators to work.

Delete some memset() that could fault on allocation failure.

Signed-off-by: Len Brown <len.brown@intel.com>

Len Brown e21c1ca3 b3cf2576

+31 -40
-30
drivers/acpi/osl.c
··· 136 136 #endif 137 137 } 138 138 139 - 140 - extern int acpi_in_resume; 141 - void *acpi_os_allocate(acpi_size size) 142 - { 143 - if (acpi_in_resume) 144 - return kmalloc(size, GFP_ATOMIC); 145 - else 146 - return kmalloc(size, GFP_KERNEL); 147 - } 148 - 149 139 acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) 150 140 { 151 141 if (efi_enabled) { ··· 1103 1113 { 1104 1114 kmem_cache_free(cache, object); 1105 1115 return (AE_OK); 1106 - } 1107 - 1108 - /******************************************************************************* 1109 - * 1110 - * FUNCTION: acpi_os_acquire_object 1111 - * 1112 - * PARAMETERS: Cache - Handle to cache object 1113 - * ReturnObject - Where the object is returned 1114 - * 1115 - * RETURN: Status 1116 - * 1117 - * DESCRIPTION: Return a zero-filled object. 1118 - * 1119 - ******************************************************************************/ 1120 - 1121 - void *acpi_os_acquire_object(acpi_cache_t * cache) 1122 - { 1123 - void *object = kmem_cache_zalloc(cache, GFP_KERNEL); 1124 - WARN_ON(!object); 1125 - return object; 1126 1116 } 1127 1117 1128 1118 /******************************************************************************
-2
drivers/acpi/parser/psutils.c
··· 139 139 /* The generic op (default) is by far the most common (16 to 1) */ 140 140 141 141 op = acpi_os_acquire_object(acpi_gbl_ps_node_cache); 142 - memset(op, 0, sizeof(struct acpi_parse_obj_common)); 143 142 } else { 144 143 /* Extended parseop */ 145 144 146 145 op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache); 147 - memset(op, 0, sizeof(struct acpi_parse_obj_named)); 148 146 } 149 147 150 148 /* Initialize the Op */
-7
drivers/acpi/pci_link.c
··· 780 780 return 0; 781 781 } 782 782 783 - /* 784 - * FIXME: this is a workaround to avoid nasty warning. It will be removed 785 - * after every device calls pci_disable_device in .resume. 786 - */ 787 - int acpi_in_resume; 788 783 static int irqrouter_resume(struct sys_device *dev) 789 784 { 790 785 struct list_head *node = NULL; ··· 789 794 /* Make sure SCI is enabled again (Apple firmware bug?) */ 790 795 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK); 791 796 792 - acpi_in_resume = 1; 793 797 list_for_each(node, &acpi_link.entries) { 794 798 link = list_entry(node, struct acpi_pci_link, node); 795 799 if (!link) { ··· 797 803 } 798 804 acpi_pci_link_resume(link); 799 805 } 800 - acpi_in_resume = 0; 801 806 return 0; 802 807 } 803 808
+2
drivers/acpi/utilities/utalloc.c
··· 285 285 return (status); 286 286 } 287 287 288 + #ifdef NOT_USED_BY_LINUX 288 289 /******************************************************************************* 289 290 * 290 291 * FUNCTION: acpi_ut_allocate ··· 361 360 362 361 return (allocation); 363 362 } 363 + #endif
+7 -1
include/acpi/acmacros.h
··· 724 724 725 725 /* Memory allocation */ 726 726 727 + #ifndef ACPI_ALLOCATE 727 728 #define ACPI_ALLOCATE(a) acpi_ut_allocate((acpi_size)(a),_COMPONENT,_acpi_module_name,__LINE__) 729 + #endif 730 + #ifndef ACPI_ALLOCATE_ZEROED 728 731 #define ACPI_ALLOCATE_ZEROED(a) acpi_ut_allocate_zeroed((acpi_size)(a), _COMPONENT,_acpi_module_name,__LINE__) 729 - #define ACPI_FREE(a) kfree(a) 732 + #endif 733 + #ifndef ACPI_FREE 734 + #define ACPI_FREE(a) acpio_os_free(a) 735 + #endif 730 736 #define ACPI_MEM_TRACKING(a) 731 737 732 738 #else
+22
include/acpi/platform/aclinux.h
··· 104 104 105 105 static inline acpi_thread_id acpi_os_get_thread_id(void) { return 0; } 106 106 107 + /* 108 + * The irqs_disabled() check is for resume from RAM. 109 + * Interrupts are off during resume, just like they are for boot. 110 + * However, boot has (system_state != SYSTEM_RUNNING) 111 + * to quiet __might_sleep() in kmalloc() and resume does not. 112 + */ 113 + #include <acpi/actypes.h> 114 + static inline void *acpi_os_allocate(acpi_size size) { 115 + return kmalloc(size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); 116 + } 117 + static inline void *acpi_os_allocate_zeroed(acpi_size size) { 118 + return kzalloc(size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); 119 + } 120 + 121 + static inline void *acpi_os_acquire_object(acpi_cache_t * cache) { 122 + return kmem_cache_zalloc(cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); 123 + } 124 + 125 + #define ACPI_ALLOCATE(a) acpi_os_allocate(a) 126 + #define ACPI_ALLOCATE_ZEROED(a) acpi_os_allocate_zeroed(a) 127 + #define ACPI_FREE(a) kfree(a) 128 + 107 129 #endif /* __ACLINUX_H__ */