Skip to contentSkip to conversation

ACPI: WMI: Driver for review

PATCH Superseded Carlos Corbacho 1 participant 4 messages Nov 10, 2007 ACPI

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover ACPI: WMI: Driver for review

As the previous 'super patch' is:

A) Pretty big
B) And because of A), hard to review

I've split it into three patches -

1) The initial WMI driver + in kernel interface
2) The sysfs interface
3) Proposed locking for sysfs (RFC)

Hopefully, it should be a bit easier to review now (there are only a few minor cleanups between this patch and the previous superpatch).

The main outstanding issues (that I know of so far - more suggestions are welcome) are:

1) Handling GUID's marked as type 'String' - The MS spec says that when this flag is set, we are supposed to change input to a method from Unicode to ASCII, and output from such a marked method from ASCII to Unicode.

What does Unicode mean in this context? I've tried reading around on the subject, but I'm not entirely clear - UCS-2 or UTF-8?

I'm also wondering if it might be better to just drop this entirely - let wmi.c only handle ASCII, and leave it up to userspace to convert to/ from whatever Unicode encoding they choose when talking to WMI-ACPI?

2) sysfs interface - is this interface acceptable as is? If not, how could it be improved?

In particular, the handling for calling a WMI method is a bit clunky, as the current interface uses two files to call a method (method_id and data) - this could be rewritten to drop the 'method' file, and assume that userspace will write a u32 with the method id followed by the rest of the input data in one go to the 'data' file?

-Carlos

Signature · 3 lines
E-Mail: [email protected]
Web: strangeworlds.co.uk
GPG Key ID: 0x23EE722D
#1 lore raw

PATCH v6 1/3 ACPI: WMI: Add WMI-ACPI mapper driver

From: Carlos Corbacho <[email protected]>

The following is an implementation of the Windows Management Instrumentation (WMI) ACPI interface mapper (PNP0C14).

What it does:

Parses the _WDG method and exports functions to process WMI method calls, data block query/ set commands (both based on GUID) and does basic event handling.

How: WMI presents two interfaces, an in kernel API and a userspace sysfs API.

Kernel: (essentially, a minimal wrapper around ACPI)

(const char *guid assume the 36 character ASCII representation of a GUID - e.g. 67C3371D-95A3-4C37-BB61-DD47B491DAAB)

wmi_evaluate_method(const char *guid, u8 instance, u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)

wmi_query_block(const char *guid, u8 instance,
struct acpi_buffer *out)

wmi_set_block(const char *guid, u38 instance,
const struct acpi_buffer *in)

wmi_install_notify_handler(acpi_notify_handler handler);

wmi_remove_notify_handler(void);

wmi_get_event_data(u32 event, struct acpi_buffer *out)

wmi_has_guid(const char guid*)

wmi_has_guid() is a helper function to find if a GUID exists or not on the system (a quick and easy way for WMI dependant drivers to see if the the method/ block they want exists, since GUIDs are supposed to be unique).

Event handling - allow a WMI based driver to register a notifier handler with WMI. When a notification is sent to WMI, the handler registered with WMI is then called (it is left to the caller to ask for the WMI event data, if needed).

What it can't do:

Unicode - The MS article[1] calls for converting between ASCII and Unicode (or vice versa) if a GUID is marked as "string". There is also another problem in that given this specification revolves around Windows, Unicode in this context likely means UTF-16. Since Linux doesn't use this, and since this driver will only be called by on Linux, it may make more sense to treat Unicode here as UTF-8 instead.

What it won't do:

Handle a MOF[1] - the WMI mapper just exports methods, data and events to userspace. MOF handling is down to userspace.

[1] http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx

===
ChangeLog
==

v1 (2007-10-02):

* Initial release

v2 (2007-10-05):

* Cleaned up code - split up super "wmi_evaluate_block" -> each external symbol now handles its own ACPI calls, rather than handing off to a "super" method (and in turn, is a lot simpler to read)
* Added a find_guid() symbol - return true if a given GUID exists on the system
* wmi_* functions now return type acpi_status (since they are just fancy wrappers around acpi_evaluate_object())
* Removed extra debug code

v3 (2007-10-27)

* More code clean up - now passes checkpatch.pl
* Change data block calls - ref MS spec, method ID is not required for them, so drop it from the function parameters.
* Const'ify guid in the function call parameters.
* Fix _WDG buffer handling - copy the data to our own private structure.
* Change WMI from tristate to bool - otherwise the external functions are not exported in linux/acpi.h if you try to build WMI as a module.
* Fix more flag comparisons.
* Add a maintainers entry - since I wrote this, I should take the blame for it.

v4 (2007-10-30)

* Add missing brace from after fixing checkpatch errors.
* Rewrote event handling - allow external drivers to register with WMI to handle WMI events
* Clean up flags and sanitise flag handling

v5 (2007-11-03)

* Add sysfs interface for userspace. Export events over netlink again.
* Remove module left overs, fully convert to built-in driver.
* Tweak in-kernel API to use u8 for instance, since this is what the GUID blocks use (so instance cannot be greater than u8).
* Export wmi_get_event_data() for in kernel WMI drivers.

v6 (2007-11-07)

* Split out userspace into a different patch

---
 MAINTAINERS           |    7 +
 drivers/acpi/Kconfig  |   11 +
 drivers/acpi/Makefile |    1 +
 drivers/acpi/wmi.c    |  576 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h  |   17 ++
 5 files changed, 612 insertions(+), 0 deletions(-)
 create mode 100644 drivers/acpi/wmi.c
MAINTAINERS +7 -0
index 1c7c229..493ba64 100644
@@ -261,6 +261,13 @@ L:	[email protected]
 W:	http://acpi.sourceforge.net/
 S:	Supported
 
+ACPI WMI DRIVER
+P:      Carlos Corbacho
+M:      [email protected]
+L:      [email protected]
+W:      http://www.lesswatts.org/projects/acpi/
+S:      Supported
+
 ADM1025 HARDWARE MONITOR DRIVER
 P:	Jean Delvare
 M:	[email protected]
drivers/acpi/Kconfig +11 -0
index da3a08f..3bdcfcf 100644
@@ -181,6 +181,17 @@ config ACPI_NUMA
 	depends on (X86 || IA64)
 	default y if IA64_GENERIC || IA64_SGI_SN2
 
+config ACPI_WMI
+	bool "WMI (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	default y
+	help
+	  This driver adds support for the WMI ACPI mapper device (PNP0C14)
+	  found on some systems.
+
+	  NOTE: You will need another driver or userspace application on top of
+	  this to actually use anything defined in the WMI ACPI mapper.
+
 config ACPI_ASUS
         tristate "ASUS/Medion Laptop Extras"
 	depends on X86
drivers/acpi/Makefile +1 -0
index 54e3ab0..9e9aa39 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_ACPI_THERMAL)	+= thermal.o
 obj-$(CONFIG_ACPI_SYSTEM)	+= system.o event.o
 obj-$(CONFIG_ACPI_DEBUG)	+= debug.o
 obj-$(CONFIG_ACPI_NUMA)		+= numa.o
+obj-$(CONFIG_ACPI_WMI)		+= wmi.o
 obj-$(CONFIG_ACPI_ASUS)		+= asus_acpi.o
 obj-$(CONFIG_ACPI_TOSHIBA)	+= toshiba_acpi.o
 obj-$(CONFIG_ACPI_HOTPLUG_MEMORY)	+= acpi_memhotplug.o
drivers/acpi/wmi.c new file +576 -0

576 lines not on this page · raw message

include/linux/acpi.h +17 -0
index 8ccedf7..36c91b3 100644
@@ -186,6 +186,23 @@ extern int ec_transaction(u8 command,
 
 #endif /*CONFIG_ACPI_EC*/
 
+#ifdef CONFIG_ACPI_WMI
+
+extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
+					u32 method_id,
+					const struct acpi_buffer *in,
+					struct acpi_buffer *out);
+extern acpi_status wmi_query_block(const char *guid, u8 instance,
+					struct acpi_buffer *out);
+extern acpi_status wmi_set_block(const char *guid, u8 instance,
+					const struct acpi_buffer *in);
+extern acpi_status wmi_install_notify_handler(acpi_notify_handler handler,
+					void *data);
+extern acpi_status wmi_remove_notify_handler(void);
+extern bool wmi_has_guid(const char *guid);
+
+#endif	/* CONFIG_ACPI_WMI */
+
 extern int acpi_blacklisted(void);
 extern void acpi_bios_year(char *s);
 
Signature · 1 line
1.5.3.4
#2 lore raw

PATCH v6 2/3 ACPI: WMI: Add sysfs userspace interface

In reply to Carlos Corbacho

From: Carlos Corbacho <[email protected]>

Userspace:

There is a userspace interface in /sys/firmware/acpi/wmi for WMI methods and data.

/sys/firmware/acpi/wmi/
|
|-> <GUID>/
|-> type (method, data, event)

Method & data blocks
|-> <instance>/
|-> data (binary data file - write input data to file, read file
to execute method or retrieve data).

Method only

    |-> method_id (write value of method id to execute)

Events - passed to userspace via netlink. However, the extra WMI data associated with an event is exposed through sysfs.

|-> notification (ACPI event value)
|-> data (binary data file - WMI data associated with the event)

---
 drivers/acpi/wmi.c |  332 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 332 insertions(+), 0 deletions(-)
drivers/acpi/wmi.c +332 -0
index 88b326b..59c3d76 100644
@@ -42,6 +42,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/types.h>
+#include <linux/sysfs.h>
 #include <acpi/acpi_drivers.h>
 
 #define ACPI_WMI_CLASS "wmi"
@@ -202,6 +203,33 @@ static bool wmi_parse_guid(const u8 *src, u8 *dest)
 	return true;
 }
 
+/*
+ * Convert a raw GUID to the ACII string representation
+ */
+static int wmi_gtoa(const char *in, char *out)
+{
+	int i;
+
+	for (i = 3; i >= 0; i--)
+		out += sprintf(out, "%02X", in[i] & 0xFF);
+
+	out += sprintf(out, "-");
+	out += sprintf(out, "%02X", in[5] & 0xFF);
+	out += sprintf(out, "%02X", in[4] & 0xFF);
+	out += sprintf(out, "-");
+	out += sprintf(out, "%02X", in[7] & 0xFF);
+	out += sprintf(out, "%02X", in[6] & 0xFF);
+	out += sprintf(out, "-");
+	out += sprintf(out, "%02X", in[8] & 0xFF);
+	out += sprintf(out, "%02X", in[9] & 0xFF);
+	out += sprintf(out, "-");
+
+	for (i = 10; i <= 15; i++)
+		out += sprintf(out, "%02X", in[i] & 0xFF);
+
+	return 0;
+}
+
 static bool find_guid(const char *guid_string, struct guid_block **out)
 {
 	char tmp[16], guid_input[16];
@@ -479,6 +507,308 @@ bool wmi_has_guid(const char *guid_string)
 }
 EXPORT_SYMBOL_GPL(wmi_has_guid);
 
+/*
+ * sysfs interface
+ */
+struct wmi_attribute {
+	struct attribute	attr;
+	ssize_t (*show)(struct kobject *kobj, char *buf);
+	ssize_t (*store)(struct kobject *kobj, const char *buf, ssize_t count);
+};
+
+#define WMI_ATTR(_name, _mode, _show, _store) \
+struct wmi_attribute wmi_attr_##_name = __ATTR(_name, _mode, _show, _store);
+
+#define to_attr(a) container_of(a, struct wmi_attribute, attr)
+
+static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+	struct wmi_attribute *wmi_attr = to_attr(attr);
+	ssize_t ret = 0;
+
+	if (wmi_attr->show)
+		ret = wmi_attr->show(kobj, buf);
+	return ret;
+}
+
+static ssize_t store(struct kobject *kobj, struct attribute *attr, const
+	char *buf, size_t count)
+{
+	struct wmi_attribute *wmi_attr = to_attr(attr);
+	ssize_t ret = 0;
+
+	if (wmi_attr->store)
+		ret = wmi_attr->store(kobj, buf, count);
+	return ret;
+}
+
+static struct sysfs_ops wmi_sysfs_ops = {
+	.show   = show,
+	.store  = store,
+};
+
+static struct kobj_type ktype_wmi = {
+	.sysfs_ops      = &wmi_sysfs_ops,
+};
+
+struct guid_kobjects {
+	struct kobject guid_kobj;
+	struct kobject *instance_kobjs;
+	struct kobject *params;
+	void *data;
+	size_t data_size;
+	u8 instances;
+	u8 method_id;
+};
+
+static struct kobject wmi_kobj;
+static struct guid_kobjects *wmi_guid_kobj;
+
+static ssize_t wmi_data_read(struct kobject *kobj, struct bin_attribute
+			*bin_attr, char *buf, loff_t offset, size_t count) {
+	u8 method_id;
+	int i;
+	u8 instance;
+	const char *guid;
+	struct guid_kobjects *gkobj;
+	struct acpi_buffer in;
+	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
+	union acpi_object *obj;
+
+	guid = kobject_name(kobj->parent);
+
+	for (i = 0; i < guids.total; i++) {
+		gkobj = &wmi_guid_kobj[i];
+		if (memcmp(kobject_name(&gkobj->guid_kobj), guid, 36) == 0) {
+			instance = simple_strtoul(kobject_name(kobj), NULL, 10);
+
+			method_id = gkobj->method_id;
+
+			if (guids.pointer[i].flags & ACPI_WMI_METHOD) {
+				if (gkobj->data) {
+					in.pointer = gkobj->data;
+					in.length = gkobj->data_size;
+					wmi_evaluate_method(guid, instance,
+						method_id, &in, &out);
+				} else {
+					wmi_evaluate_method(guid, instance,
+						method_id, NULL, &out);
+				}
+				break;
+			} else {
+				wmi_query_block(guid, instance, &out);
+				break;
+			}
+		}
+	}
+
+	obj = (union acpi_object *) out.pointer;
+	buf = obj->buffer.pointer;
+
+	return 0;
+}
+
+static ssize_t wmi_data_write(struct kobject *kobj, struct bin_attribute
+			*bin_attr, char *buf, loff_t offset, size_t count){
+	int i;
+
+	for (i = 0; i < guids.total; i++) {
+		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
+				kobject_name(kobj->parent), 36) == 0) {
+			kfree(wmi_guid_kobj[i].data);
+			wmi_guid_kobj[i].data = kzalloc(count, GFP_KERNEL);
+			memcpy(wmi_guid_kobj[i].data, buf, count);
+			wmi_guid_kobj[i].data_size = count;
+			return count;
+		}
+	}
+	return -EINVAL;
+}
+
+static struct bin_attribute wmi_attr_data = {
+	.attr = {.name = "data", .mode = 0600},
+	.size = 0,
+	.read = wmi_data_read,
+	.write = wmi_data_write,
+};
+
+static ssize_t wmi_event_data_read(struct kobject *kobj, struct bin_attribute
+			*bin_attr, char *buf, loff_t offset, size_t count) {
+	int i;
+	const char *guid;
+	struct guid_kobjects *gkobj;
+	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
+	union acpi_object *obj;
+
+	guid = kobject_name(kobj->parent);
+
+	for (i = 0; i < guids.total; i++) {
+		gkobj = &wmi_guid_kobj[i];
+		if (memcmp(kobject_name(&gkobj->guid_kobj), guid, 36) == 0)
+			wmi_get_event_data(guids.pointer[i].notify_id, &out);
+	}
+
+	obj = (union acpi_object *) out.pointer;
+	buf = obj->buffer.pointer;
+
+	return 0;
+}
+
+static struct bin_attribute wmi_attr_event_data = {
+	.attr = {.name = "data", .mode = 0400},
+	.size = 0,
+	.read = wmi_event_data_read,
+};
+
+/* sysfs calls */
+static ssize_t
+show_guid_type(struct kobject *kobj, char *buf)
+{
+	struct guid_block *block;
+
+	find_guid(kobject_name(kobj), &block);
+
+	if (block->flags & ACPI_WMI_METHOD) {
+		return sprintf(buf, "method\n");
+	} else if (block->flags & ACPI_WMI_EVENT) {
+		return sprintf(buf, "event\n");
+	} else {
+		return sprintf(buf, "data\n");
+	}
+}
+static WMI_ATTR(type, S_IRUGO, show_guid_type, NULL);
+
+static ssize_t show_guid_method_id(struct kobject *kobj, char *buf)
+{
+	int i;
+
+	for (i = 0; i < guids.total; i++) {
+		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
+			kobject_name(kobj->parent), 36) == 0)
+			return sprintf(buf, "%d\n", wmi_guid_kobj[i].method_id);
+	}
+	return sprintf(buf, "Error\n");
+}
+
+static ssize_t set_guid_method_id(struct kobject *kobj, const char *buf,
+	ssize_t count)
+{
+	int i;
+	u8 method_id;
+
+	method_id = simple_strtoul(buf, NULL, 10);
+
+	for (i = 0; i < guids.total; i++) {
+		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
+			kobject_name(kobj->parent), 36) == 0) {
+			wmi_guid_kobj[i].method_id = method_id;
+			return count;
+		}
+	}
+	return -EINVAL;
+}
+static WMI_ATTR(method_id, S_IWUGO | S_IRUGO, show_guid_method_id,
+	set_guid_method_id);
+
+static ssize_t show_event_notification(struct kobject *kobj, char *buf)
+{
+	int i;
+
+	for (i = 0; i < guids.total; i++) {
+		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
+			kobject_name(kobj), 36) == 0)
+			return sprintf(buf, "%d\n",
+				guids.pointer[i].notify_id & 0xFF);
+	}
+	return sprintf(buf, "Error\n");
+}
+static WMI_ATTR(notification, S_IRUGO, show_event_notification, NULL);
+
+static int wmi_sysfs_init(void)
+{
+	int i, j, result;
+	u8 instances;
+	char guid_string[37];
+	char temp[4];
+	struct kobject *guid_kobj;
+	struct kobject *instance_kobjs;
+	struct guid_block *block;
+
+	wmi_guid_kobj = kzalloc(sizeof(struct guid_kobjects) * guids.total,
+		GFP_KERNEL);
+
+	wmi_kobj.parent = &acpi_subsys.kobj;
+	wmi_kobj.ktype = &ktype_wmi;
+	kobject_set_name(&wmi_kobj, "wmi");
+
+	result = kobject_register(&wmi_kobj);
+	if (result)
+		return result;
+
+	/* Create directories for all the GUIDs */
+	for (i = 0; i < guids.total; i++) {
+		guid_kobj = &wmi_guid_kobj[i].guid_kobj;
+		guid_kobj->parent = &wmi_kobj;
+		guid_kobj->ktype = &ktype_wmi;
+
+		block = guids.pointer + i;
+		wmi_gtoa(block->guid, guid_string);
+		kobject_set_name(guid_kobj, guid_string);
+
+		result = kobject_register(guid_kobj);
+		if (result)
+			return result;
+
+		result = sysfs_create_file(guid_kobj, &wmi_attr_type.attr);
+		if (result)
+			return result;
+
+		if (guids.pointer[i].flags & ACPI_WMI_EVENT) {
+			result = sysfs_create_file(guid_kobj,
+				&wmi_attr_notification.attr);
+			if (result)
+				return result;
+
+			result = sysfs_create_bin_file(guid_kobj,
+				&wmi_attr_event_data);
+			if (result)
+				return result;
+			break;
+		}
+
+		/* Create directories for all the instances */
+		instances = guids.pointer[i].instance_count;
+		wmi_guid_kobj[i].instances = instances;
+		wmi_guid_kobj[i].instance_kobjs = kzalloc(sizeof(struct kobject)
+			* instances, GFP_KERNEL);
+		instance_kobjs = wmi_guid_kobj[i].instance_kobjs;
+		for (j = 0; j < instances; j++) {
+			instance_kobjs[j].parent = guid_kobj;
+			instance_kobjs[j].ktype = &ktype_wmi;
+			sprintf(temp, "%d", j+1);
+			kobject_set_name(&instance_kobjs[j], temp);
+
+			result = kobject_register(&instance_kobjs[j]);
+			if (result)
+				return result;
+
+			/* Create the relevant files under each instance */
+			result = sysfs_create_bin_file(&instance_kobjs[j],
+				&wmi_attr_data);
+			if (result)
+				return result;
+
+			if (guids.pointer[i].flags & ACPI_WMI_METHOD) {
+				result = sysfs_create_file(&instance_kobjs[j],
+					&wmi_attr_method_id.attr);
+				if (result)
+					return result;
+			}
+		}
+	}
+	return 0;
+}
+
 /**
  * parse_wdg - Parse the _WDG method for the GUID data blocks
  */
@@ -551,6 +881,8 @@ static int __init acpi_wmi_add(struct acpi_device *device)
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 
+	result = wmi_sysfs_init();
+
 	return result;
 }
 
Signature · 1 line
1.5.3.4
#3 lore raw

RFC PATCH v6 3/3 ACPI: WMI: Add locking to sysfs files for methods and data

In reply to Carlos Corbacho

From: Carlos Corbacho <[email protected]>

To ensure that we don't start overwriting the method_id or input data when executing methods, or handling data GUID's, add a mutex lock around data read/ write and method_id write sysfs functions.

---
 drivers/acpi/wmi.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/acpi/wmi.c +17 -0
index 59c3d76..e210973 100644
@@ -43,6 +43,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/sysfs.h>
+#include <linux/mutex.h>
 #include <acpi/acpi_drivers.h>
 
 #define ACPI_WMI_CLASS "wmi"
@@ -50,6 +51,8 @@
 #undef PREFIX
 #define PREFIX "ACPI: WMI: "
 
+static DEFINE_MUTEX(wmi_data_lock);
+
 struct guid_block
 {
 	char guid[16];
@@ -577,6 +580,8 @@ static ssize_t wmi_data_read(struct kobject *kobj, struct bin_attribute
 
 	guid = kobject_name(kobj->parent);
 
+	mutex_lock(&wmi_data_lock);
+
 	for (i = 0; i < guids.total; i++) {
 		gkobj = &wmi_guid_kobj[i];
 		if (memcmp(kobject_name(&gkobj->guid_kobj), guid, 36) == 0) {
@@ -605,6 +610,8 @@ static ssize_t wmi_data_read(struct kobject *kobj, struct bin_attribute
 	obj = (union acpi_object *) out.pointer;
 	buf = obj->buffer.pointer;
 
+	mutex_unlock(&wmi_data_lock);
+
 	return 0;
 }
 
@@ -612,6 +619,8 @@ static ssize_t wmi_data_write(struct kobject *kobj, struct bin_attribute
 			*bin_attr, char *buf, loff_t offset, size_t count){
 	int i;
 
+	mutex_lock(&wmi_data_lock);
+
 	for (i = 0; i < guids.total; i++) {
 		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
 				kobject_name(kobj->parent), 36) == 0) {
@@ -619,9 +628,11 @@ static ssize_t wmi_data_write(struct kobject *kobj, struct bin_attribute
 			wmi_guid_kobj[i].data = kzalloc(count, GFP_KERNEL);
 			memcpy(wmi_guid_kobj[i].data, buf, count);
 			wmi_guid_kobj[i].data_size = count;
+			mutex_unlock(&wmi_data_lock);
 			return count;
 		}
 	}
+	mutex_unlock(&wmi_data_lock);
 	return -EINVAL;
 }
 
@@ -698,13 +709,19 @@ static ssize_t set_guid_method_id(struct kobject *kobj, const char *buf,
 
 	method_id = simple_strtoul(buf, NULL, 10);
 
+	mutex_lock(&wmi_data_lock);
+
 	for (i = 0; i < guids.total; i++) {
 		if (memcmp(kobject_name(&wmi_guid_kobj[i].guid_kobj),
 			kobject_name(kobj->parent), 36) == 0) {
 			wmi_guid_kobj[i].method_id = method_id;
+			mutex_unlock(&wmi_data_lock);
 			return count;
 		}
 	}
+
+	mutex_unlock(&wmi_data_lock);
+
 	return -EINVAL;
 }
 static WMI_ATTR(method_id, S_IWUGO | S_IRUGO, show_guid_method_id,
Signature · 1 line
1.5.3.4