Skip to contentSkip to conversation

platform/x86: alienware-wmi-base: Transition to new WMI API

PATCH Superseded Kurt Borja 2 participants 3 messages Mar 31

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kurt Borja

author maintainer
#0 lore raw

PATCH v2 1/1 platform/x86: alienware-wmi-base: Transition to new WMI API

Transition to the new wmi_buffer based WMI API.

---
v2:
- Cast wmi_buffer data to __le32 and then use le32_to_cpu() before returning

v1: https://patch.msgid.link/[email protected]

---
 drivers/platform/x86/dell/alienware-wmi-base.c | 32 +++++++++++++++-----------
 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/platform/x86/dell/alienware-wmi-base.c +19 -13
index 64562b92314f..9abdc5de8e23 100644
@@ -9,11 +9,13 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/acpi.h>
-#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/dmi.h>
 #include <linux/leds.h>
+
+#include <asm/byteorder.h>
+
 #include "alienware-wmi.h"
 
 MODULE_AUTHOR("Mario Limonciello <[email protected]>");
@@ -150,23 +152,27 @@ u8 alienware_interface;
 int alienware_wmi_command(struct wmi_device *wdev, u32 method_id,
 			  void *in_args, size_t in_size, u32 *out_data)
 {
-	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
-	struct acpi_buffer in = {in_size, in_args};
-	acpi_status ret;
+	struct wmi_buffer out, in = {
+		.data = in_args,
+		.length = in_size,
+	};
+	int ret;
 
-	ret = wmidev_evaluate_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
-	if (ACPI_FAILURE(ret))
-		return -EIO;
+	ret = wmidev_invoke_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
+	if (ret)
+		return ret;
 
-	union acpi_object *obj __free(kfree) = out.pointer;
+	if (!out_data)
+		return 0;
 
-	if (out_data) {
-		if (obj && obj->type == ACPI_TYPE_INTEGER)
-			*out_data = (u32)obj->integer.value;
-		else
-			return -ENOMSG;
+	if (out.length < sizeof(*out_data)) {
+		kfree(out.data);
+		return -ENOMSG;
 	}
 
+	*out_data = le32_to_cpu(*(__le32 *)out.data);
+	kfree(out.data);
+
 	return 0;
 }
 

---
base-commit: fab7c51693e95aa874d6d9db22bfae7bd0b23c66
change-id: 20260123-aw-new-api-1c18f1011f35

Signature · 2 lines
Thanks, 
 ~ Kurt
maintainer
#1 lore raw
Quoted 58 lines · Kurt Borja

Transition to the new wmi_buffer based WMI API.

---
v2:
- Cast wmi_buffer data to __le32 and then use le32_to_cpu() before returning

v1: https://patch.msgid.link/[email protected]

---
 drivers/platform/x86/dell/alienware-wmi-base.c | 32 +++++++++++++++-----------
 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/platform/x86/dell/alienware-wmi-base.c +13 -10
index 64562b92314f..9abdc5de8e23 100644
@@ -9,11 +9,13 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/acpi.h>
-#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/dmi.h>
 #include <linux/leds.h>
+
+#include <asm/byteorder.h>
+
 #include "alienware-wmi.h"
 
 MODULE_AUTHOR("Mario Limonciello <[email protected]>");
@@ -150,23 +152,27 @@ u8 alienware_interface;
 int alienware_wmi_command(struct wmi_device *wdev, u32 method_id,
 			  void *in_args, size_t in_size, u32 *out_data)
 {
-	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
-	struct acpi_buffer in = {in_size, in_args};
-	acpi_status ret;
+	struct wmi_buffer out, in = {
+		.data = in_args,
+		.length = in_size,
+	};
+	int ret;
 
-	ret = wmidev_evaluate_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
-	if (ACPI_FAILURE(ret))
-		return -EIO;
+	ret = wmidev_invoke_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
+	if (ret)
+		return ret;
 
-	union acpi_object *obj __free(kfree) = out.pointer;
+	if (!out_data)
+		return 0;
 
-	if (out_data) {
-		if (obj && obj->type == ACPI_TYPE_INTEGER)

drivers/platform/x86/dell/alienware-wmi-base.c u8 alienware_interface; · line 174

Quoted 10 lines
drivers/platform/x86/dell/alienware-wmi-base.c +5 -3
-			*out_data = (u32)obj->integer.value;
-		else
-			return -ENOMSG;
+	if (out.length < sizeof(*out_data)) {
+		kfree(out.data);
+		return -ENOMSG;
 	}
 
+	*out_data = le32_to_cpu(*(__le32 *)out.data);
+	kfree(out.data);

Hi,

Please don't bring back duplicated kfree() calls. Just assign out.data into a local variable so you can use __free() for it similar to what the old code did.

Signature · 1 line
 i.
author maintainer
#2 lore raw
Quoted 68 lines · Ilpo Järvinen
Quoted 66 lines · Kurt Borja

Transition to the new wmi_buffer based WMI API.

---
v2:
- Cast wmi_buffer data to __le32 and then use le32_to_cpu() before returning

v1: https://patch.msgid.link/[email protected]

---
 drivers/platform/x86/dell/alienware-wmi-base.c | 32 +++++++++++++++-----------
 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/platform/x86/dell/alienware-wmi-base.c +16 -13
index 64562b92314f..9abdc5de8e23 100644
@@ -9,11 +9,13 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/acpi.h>
-#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/dmi.h>
 #include <linux/leds.h>
+
+#include <asm/byteorder.h>
+
 #include "alienware-wmi.h"
 
 MODULE_AUTHOR("Mario Limonciello <[email protected]>");
@@ -150,23 +152,27 @@ u8 alienware_interface;
 int alienware_wmi_command(struct wmi_device *wdev, u32 method_id,
 			  void *in_args, size_t in_size, u32 *out_data)
 {
-	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
-	struct acpi_buffer in = {in_size, in_args};
-	acpi_status ret;
+	struct wmi_buffer out, in = {
+		.data = in_args,
+		.length = in_size,
+	};
+	int ret;
 
-	ret = wmidev_evaluate_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
-	if (ACPI_FAILURE(ret))
-		return -EIO;
+	ret = wmidev_invoke_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
+	if (ret)
+		return ret;
 
-	union acpi_object *obj __free(kfree) = out.pointer;
+	if (!out_data)
+		return 0;
 
-	if (out_data) {
-		if (obj && obj->type == ACPI_TYPE_INTEGER)
-			*out_data = (u32)obj->integer.value;
-		else
-			return -ENOMSG;
+	if (out.length < sizeof(*out_data)) {
+		kfree(out.data);
+		return -ENOMSG;
 	}
 
Quoted 8 lines

drivers/platform/x86/dell/alienware-wmi-base.c u8 alienware_interface; · line 174

Quoted 2 lines
drivers/platform/x86/dell/alienware-wmi-base.c +2 -0
+	*out_data = le32_to_cpu(*(__le32 *)out.data);
+	kfree(out.data);

Hi,

Please don't bring back duplicated kfree() calls. Just assign out.data into a local variable so you can use __free() for it similar to what the old code did.

Hi Ilpo,

Sure! I'll use __free() again.

Signature · 2 lines
Thanks,
 ~ Kurt