From 2c6719a3ef2f7da59a622ba1176ad41d553f8f43 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 15 May 2010 23:22:18 +0200 Subject: drivers/platform/x86: Use kmemdup Use kmemdup when some other buffer is immediately copied into the allocated region. A simplified version of the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // @@ expression from,to,size,flag; statement S; @@ - to = \(kmalloc\|kzalloc\)(size,flag); + to = kmemdup(from,size,flag); if (to==NULL || ...) S - memcpy(to, from, size); // Signed-off-by: Julia Lawall --- drivers/platform/x86/wmi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/platform/x86/wmi.c') diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 39ec5b6c2e3..17df134a6f0 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -756,12 +756,10 @@ static __init acpi_status parse_wdg(acpi_handle handle) total = obj->buffer.length / sizeof(struct guid_block); - gblock = kzalloc(obj->buffer.length, GFP_KERNEL); + gblock = kmemdup(obj->buffer.pointer, obj->buffer.length, GFP_KERNEL); if (!gblock) return AE_NO_MEMORY; - memcpy(gblock, obj->buffer.pointer, obj->buffer.length); - for (i = 0; i < total; i++) { /* Some WMI devices, like those for nVidia hooks, have a -- cgit v1.2.3-70-g09d2 From fc3155b2c6419a442c6f8b34a3bf31f8efe0fe33 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Mon, 3 May 2010 15:30:15 +0200 Subject: X86 platform wmi: Introduce debug param to log all WMI events To give people easily an idea what could be WMI driven on their system. Introduces: wmi.debug=[01] Tested on an acer: ACPI: WMI: DEBUG Event INTEGER_TYPE - 65535 Situation where a driver registers for specific event and debug handler gets overridden and set again if the registering driver gets unloaded again is untested, but should work. Signed-off-by: Thomas Renninger CC: platform-driver-x86@vger.kernel.org CC: mjg59@srcf.ucam.org CC: corentin.chary@gmail.com Signed-off-by: Carlos Corbacho Signed-off-by: Matthew Garrett --- drivers/platform/x86/wmi.c | 58 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'drivers/platform/x86/wmi.c') diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 17df134a6f0..e820f4cddb6 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -81,6 +81,11 @@ static struct wmi_block wmi_blocks; #define ACPI_WMI_STRING 0x4 /* GUID takes & returns a string */ #define ACPI_WMI_EVENT 0x8 /* GUID is an event */ +static int debug_event; +module_param(debug_event, bool, 0444); +MODULE_PARM_DESC(debug_event, + "Log WMI Events [0/1]"); + static int acpi_wmi_remove(struct acpi_device *device, int type); static int acpi_wmi_add(struct acpi_device *device); static void acpi_wmi_notify(struct acpi_device *device, u32 event); @@ -477,6 +482,37 @@ const struct acpi_buffer *in) } EXPORT_SYMBOL_GPL(wmi_set_block); +static void wmi_notify_debug(u32 value, void *context) +{ + struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + + wmi_get_event_data(value, &response); + + obj = (union acpi_object *)response.pointer; + + if (!obj) + return; + + printk(KERN_INFO PREFIX "DEBUG Event "); + switch(obj->type) { + case ACPI_TYPE_BUFFER: + printk("BUFFER_TYPE - length %d\n", obj->buffer.length); + break; + case ACPI_TYPE_STRING: + printk("STRING_TYPE - %s\n", obj->string.pointer); + break; + case ACPI_TYPE_INTEGER: + printk("INTEGER_TYPE - %llu\n", obj->integer.value); + break; + case ACPI_TYPE_PACKAGE: + printk("PACKAGE_TYPE - %d elements\n", obj->package.count); + break; + default: + printk("object type 0x%X\n", obj->type); + } +} + /** * wmi_install_notify_handler - Register handler for WMI events * @handler: Function to handle notifications @@ -496,7 +532,7 @@ wmi_notify_handler handler, void *data) if (!find_guid(guid, &block)) return AE_NOT_EXIST; - if (block->handler) + if (block->handler && block->handler != wmi_notify_debug) return AE_ALREADY_ACQUIRED; block->handler = handler; @@ -516,7 +552,7 @@ EXPORT_SYMBOL_GPL(wmi_install_notify_handler); acpi_status wmi_remove_notify_handler(const char *guid) { struct wmi_block *block; - acpi_status status; + acpi_status status = AE_OK; if (!guid) return AE_BAD_PARAMETER; @@ -524,14 +560,16 @@ acpi_status wmi_remove_notify_handler(const char *guid) if (!find_guid(guid, &block)) return AE_NOT_EXIST; - if (!block->handler) + if (!block->handler || block->handler == wmi_notify_debug) return AE_NULL_ENTRY; - status = wmi_method_enable(block, 0); - - block->handler = NULL; - block->handler_data = NULL; - + if (debug_event) { + block->handler = wmi_notify_debug; + } else { + status = wmi_method_enable(block, 0); + block->handler = NULL; + block->handler_data = NULL; + } return status; } EXPORT_SYMBOL_GPL(wmi_remove_notify_handler); @@ -780,6 +818,10 @@ static __init acpi_status parse_wdg(acpi_handle handle) wblock->gblock = gblock[i]; wblock->handle = handle; + if (debug_event) { + wblock->handler = wmi_notify_debug; + status = wmi_method_enable(wblock, 1); + } list_add_tail(&wblock->list, &wmi_blocks.list); } -- cgit v1.2.3-70-g09d2 From 7715348cbe28da80fd5372fd68748e852a9d8468 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Mon, 3 May 2010 15:30:16 +0200 Subject: X86 platform wmi: Also log GUID string when an event happens and debug is set Output in log with debug=1: ACPI: WMI: DEBUG Event INTEGER_TYPE - 65535 ACPI: WMI: DEBUG Event GUID: CC1A61AC-4256-41A3-B9E0-05A445ADE2F5 Signed-off-by: Thomas Renninger CC: platform-driver-x86@vger.kernel.org CC: mjg59@srcf.ucam.org CC: corentin.chary@gmail.com Signed-off-by: Carlos Corbacho Signed-off-by: Matthew Garrett --- drivers/platform/x86/wmi.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/platform/x86/wmi.c') diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index e820f4cddb6..f16768db446 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -880,6 +880,7 @@ static void acpi_wmi_notify(struct acpi_device *device, u32 event) struct guid_block *block; struct wmi_block *wblock; struct list_head *p; + char guid_string[37]; list_for_each(p, &wmi_blocks.list) { wblock = list_entry(p, struct wmi_block, list); @@ -889,6 +890,11 @@ static void acpi_wmi_notify(struct acpi_device *device, u32 event) (block->notify_id == event)) { if (wblock->handler) wblock->handler(event, wblock->handler_data); + if (debug_event) { + wmi_gtoa(wblock->gblock.guid, guid_string); + printk(KERN_INFO PREFIX "DEBUG Event GUID:" + " %s\n", guid_string); + } acpi_bus_generate_netlink_event( device->pnp.device_class, dev_name(&device->dev), -- cgit v1.2.3-70-g09d2 From a929aae0e0a91d89b60774316ede6c1e2e10dc4e Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Mon, 3 May 2010 15:30:17 +0200 Subject: X86 platfrom wmi: Add debug facility to dump WMI data in a readable way Signed-off-by: Thomas Renninger CC: platform-driver-x86@vger.kernel.org CC: mjg59@srcf.ucam.org CC: corentin.chary@gmail.com Signed-off-by: Carlos Corbacho Signed-off-by: Matthew Garrett --- drivers/platform/x86/wmi.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'drivers/platform/x86/wmi.c') diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index f16768db446..e4eaa14ed98 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -86,6 +86,11 @@ module_param(debug_event, bool, 0444); MODULE_PARM_DESC(debug_event, "Log WMI Events [0/1]"); +static int debug_dump_wdg; +module_param(debug_dump_wdg, bool, 0444); +MODULE_PARM_DESC(debug_dump_wdg, + "Dump available WMI interfaces [0/1]"); + static int acpi_wmi_remove(struct acpi_device *device, int type); static int acpi_wmi_add(struct acpi_device *device); static void acpi_wmi_notify(struct acpi_device *device, u32 event); @@ -482,6 +487,33 @@ const struct acpi_buffer *in) } EXPORT_SYMBOL_GPL(wmi_set_block); +static void wmi_dump_wdg(struct guid_block *g) +{ + char guid_string[37]; + + wmi_gtoa(g->guid, guid_string); + printk(KERN_INFO PREFIX "%s:\n", guid_string); + printk(KERN_INFO PREFIX "\tobject_id: %c%c\n", + g->object_id[0], g->object_id[1]); + printk(KERN_INFO PREFIX "\tnotify_id: %02X\n", g->notify_id); + printk(KERN_INFO PREFIX "\treserved: %02X\n", g->reserved); + printk(KERN_INFO PREFIX "\tinstance_count: %d\n", g->instance_count); + printk(KERN_INFO PREFIX "\tflags: %#x", g->flags); + if (g->flags) { + printk(" "); + if (g->flags & ACPI_WMI_EXPENSIVE) + printk("ACPI_WMI_EXPENSIVE "); + if (g->flags & ACPI_WMI_METHOD) + printk("ACPI_WMI_METHOD "); + if (g->flags & ACPI_WMI_STRING) + printk("ACPI_WMI_STRING "); + if (g->flags & ACPI_WMI_EVENT) + printk("ACPI_WMI_EVENT "); + } + printk("\n"); + +} + static void wmi_notify_debug(u32 value, void *context) { struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -812,6 +844,9 @@ static __init acpi_status parse_wdg(acpi_handle handle) guid_string); continue; } + if (debug_dump_wdg) + wmi_dump_wdg(&gblock[i]); + wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); if (!wblock) return AE_NO_MEMORY; -- cgit v1.2.3-70-g09d2