From: Antheas Kapenekakis <lkml@antheas.dev>
To: platform-driver-x86@vger.kernel.org
Cc: "Armin Wolf" <W_Armin@gmx.de>, "Jonathan Corbet" <corbet@lwn.net>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Jean Delvare" <jdelvare@suse.com>,
"Guenter Roeck" <linux@roeck-us.net>,
"Kurt Borja" <kuurtb@gmail.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hwmon@vger.kernel.org,
"Antheas Kapenekakis" <lkml@antheas.dev>
Subject: [PATCH v1 01/10] platform/x86: msi-wmi-platform: Use input buffer for returning result
Date: Sun, 11 May 2025 22:44:18 +0200 [thread overview]
Message-ID: <20250511204427.327558-2-lkml@antheas.dev> (raw)
In-Reply-To: <20250511204427.327558-1-lkml@antheas.dev>
From: Armin Wolf <W_Armin@gmx.de>
Modify msi_wmi_platform_query() to reuse the input buffer for
returning the result of a WMI method call. Using a separate output
buffer to return the result is unnecessary because the WMI interface
requires both buffers to have the same length anyway.
Co-developed-by: Antheas Kapenekakis <lkml@antheas.dev>
Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/x86/msi-wmi-platform.c | 53 ++++++++++++-------------
1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/drivers/platform/x86/msi-wmi-platform.c b/drivers/platform/x86/msi-wmi-platform.c
index dc5e9878cb682..41218a9d6e35d 100644
--- a/drivers/platform/x86/msi-wmi-platform.c
+++ b/drivers/platform/x86/msi-wmi-platform.c
@@ -21,6 +21,7 @@
#include <linux/mutex.h>
#include <linux/printk.h>
#include <linux/rwsem.h>
+#include <linux/string.h>
#include <linux/types.h>
#include <linux/wmi.h>
@@ -140,19 +141,19 @@ static int msi_wmi_platform_parse_buffer(union acpi_object *obj, u8 *output, siz
}
static int msi_wmi_platform_query(struct msi_wmi_platform_data *data,
- enum msi_wmi_platform_method method, u8 *input,
- size_t input_length, u8 *output, size_t output_length)
+ enum msi_wmi_platform_method method, u8 *buffer,
+ size_t length)
{
struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer in = {
- .length = input_length,
- .pointer = input
+ .length = length,
+ .pointer = buffer
};
union acpi_object *obj;
acpi_status status;
int ret;
- if (!input_length || !output_length)
+ if (!length)
return -EINVAL;
/*
@@ -169,7 +170,7 @@ static int msi_wmi_platform_query(struct msi_wmi_platform_data *data,
if (!obj)
return -ENODATA;
- ret = msi_wmi_platform_parse_buffer(obj, output, output_length);
+ ret = msi_wmi_platform_parse_buffer(obj, buffer, length);
kfree(obj);
return ret;
@@ -185,17 +186,15 @@ static int msi_wmi_platform_read(struct device *dev, enum hwmon_sensor_types typ
int channel, long *val)
{
struct msi_wmi_platform_data *data = dev_get_drvdata(dev);
- u8 input[32] = { 0 };
- u8 output[32];
+ u8 buffer[32] = { 0 };
u16 value;
int ret;
- ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_FAN, input, sizeof(input), output,
- sizeof(output));
+ ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_FAN, buf, sizeof(buf));
if (ret < 0)
return ret;
- value = get_unaligned_be16(&output[channel * 2 + 1]);
+ value = get_unaligned_be16(&buffer[channel * 2 + 1]);
if (!value)
*val = 0;
else
@@ -245,13 +244,17 @@ static ssize_t msi_wmi_platform_write(struct file *fp, const char __user *input,
return ret;
down_write(&data->buffer_lock);
- ret = msi_wmi_platform_query(data->data, data->method, payload, data->length, data->buffer,
+ ret = msi_wmi_platform_query(data->data, data->method, data->buffer,
data->length);
up_write(&data->buffer_lock);
if (ret < 0)
return ret;
+ down_write(&data->buffer_lock);
+ memcpy(data->buffer, payload, data->length);
+ up_write(&data->buffer_lock);
+
return length;
}
@@ -348,23 +351,21 @@ static int msi_wmi_platform_hwmon_init(struct msi_wmi_platform_data *data)
static int msi_wmi_platform_ec_init(struct msi_wmi_platform_data *data)
{
- u8 input[32] = { 0 };
- u8 output[32];
+ u8 buffer[32] = { 0 };
u8 flags;
int ret;
- ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_EC, input, sizeof(input), output,
- sizeof(output));
+ ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_EC, buffer, sizeof(buffer));
if (ret < 0)
return ret;
- flags = output[MSI_PLATFORM_EC_FLAGS_OFFSET];
+ flags = buffer[MSI_PLATFORM_EC_FLAGS_OFFSET];
dev_dbg(&data->wdev->dev, "EC RAM version %lu.%lu\n",
FIELD_GET(MSI_PLATFORM_EC_MAJOR_MASK, flags),
FIELD_GET(MSI_PLATFORM_EC_MINOR_MASK, flags));
dev_dbg(&data->wdev->dev, "EC firmware version %.28s\n",
- &output[MSI_PLATFORM_EC_VERSION_OFFSET]);
+ &buffer[MSI_PLATFORM_EC_VERSION_OFFSET]);
if (!(flags & MSI_PLATFORM_EC_IS_TIGERLAKE)) {
if (!force)
@@ -378,27 +379,25 @@ static int msi_wmi_platform_ec_init(struct msi_wmi_platform_data *data)
static int msi_wmi_platform_init(struct msi_wmi_platform_data *data)
{
- u8 input[32] = { 0 };
- u8 output[32];
+ u8 buffer[32] = { 0 };
int ret;
- ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_WMI, input, sizeof(input), output,
- sizeof(output));
+ ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_WMI, buffer, sizeof(buffer));
if (ret < 0)
return ret;
dev_dbg(&data->wdev->dev, "WMI interface version %u.%u\n",
- output[MSI_PLATFORM_WMI_MAJOR_OFFSET],
- output[MSI_PLATFORM_WMI_MINOR_OFFSET]);
+ buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET],
+ buffer[MSI_PLATFORM_WMI_MINOR_OFFSET]);
- if (output[MSI_PLATFORM_WMI_MAJOR_OFFSET] != MSI_WMI_PLATFORM_INTERFACE_VERSION) {
+ if (buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET] != MSI_WMI_PLATFORM_INTERFACE_VERSION) {
if (!force)
return -ENODEV;
dev_warn(&data->wdev->dev,
"Loading despite unsupported WMI interface version (%u.%u)\n",
- output[MSI_PLATFORM_WMI_MAJOR_OFFSET],
- output[MSI_PLATFORM_WMI_MINOR_OFFSET]);
+ buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET],
+ buffer[MSI_PLATFORM_WMI_MINOR_OFFSET]);
}
return 0;
--
2.49.0
next prev parent reply other threads:[~2025-05-11 20:53 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 20:44 [PATCH v1 00/10] platform/x86: msi-wmi-platform: Add fan curves/platform profile/tdp/battery limiting Antheas Kapenekakis
2025-05-11 20:44 ` Antheas Kapenekakis [this message]
2025-05-11 23:31 ` [PATCH v1 01/10] platform/x86: msi-wmi-platform: Use input buffer for returning result Kurt Borja
2025-05-13 19:42 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 02/10] platform/x86: msi-wmi-platform: Add unlocked msi_wmi_platform_query Antheas Kapenekakis
2025-05-12 19:21 ` Kurt Borja
2025-05-12 20:51 ` Antheas Kapenekakis
2025-05-12 21:23 ` Kurt Borja
2025-05-12 21:51 ` Antheas Kapenekakis
2025-05-13 19:45 ` Armin Wolf
2025-05-13 19:47 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 03/10] platform/x86: msi-wmi-platform: Add quirk system Antheas Kapenekakis
2025-05-11 23:32 ` Kurt Borja
2025-05-13 20:43 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 04/10] platform/x86: msi-wmi-platform: Add support for fan control Antheas Kapenekakis
2025-05-11 23:32 ` Kurt Borja
2025-05-13 20:58 ` Armin Wolf
2025-05-19 1:35 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 05/10] platform/x86: msi-wmi-platform: Add platform profile through shift mode Antheas Kapenekakis
2025-05-11 23:33 ` Kurt Borja
2025-05-12 21:59 ` Antheas Kapenekakis
2025-05-19 1:51 ` Armin Wolf
2025-05-19 1:58 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 06/10] platform/x86: msi-wmi-platform: Add PL1/PL2 support via firmware attributes Antheas Kapenekakis
2025-05-11 23:34 ` Kurt Borja
2025-05-12 10:22 ` Antheas Kapenekakis
2025-05-19 2:08 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 07/10] platform/x86: msi-wmi-platform: Add charge_threshold support Antheas Kapenekakis
2025-05-11 23:34 ` Kurt Borja
2025-05-19 2:32 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 08/10] platform/x86: msi-wmi-platform: Drop excess fans in dual fan devices Antheas Kapenekakis
2025-05-11 23:35 ` Kurt Borja
2025-05-11 20:44 ` [PATCH v1 09/10] platform/x86: msi-wmi-platform: Update header text Antheas Kapenekakis
2025-05-19 2:33 ` Armin Wolf
2025-05-11 20:44 ` [PATCH v1 10/10] platform/x86: msi-wmi-platform: Restore fan curves on PWM disable and unload Antheas Kapenekakis
2025-05-12 19:16 ` Kurt Borja
2025-05-12 20:50 ` Antheas Kapenekakis
2025-05-11 23:30 ` [PATCH v1 00/10] platform/x86: msi-wmi-platform: Add fan curves/platform profile/tdp/battery limiting Kurt Borja
2025-05-12 10:16 ` Antheas Kapenekakis
2025-05-12 19:05 ` Kurt Borja
2025-05-19 2:37 ` Armin Wolf
2025-05-30 20:50 ` Antheas Kapenekakis
2025-05-30 21:15 ` Armin Wolf
2025-05-30 21:28 ` Antheas Kapenekakis
2025-05-30 22:00 ` Armin Wolf
2026-05-08 18:41 ` Derek J. Clark
2026-05-09 17:25 ` Antheas Kapenekakis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250511204427.327558-2-lkml@antheas.dev \
--to=lkml@antheas.dev \
--cc=W_Armin@gmx.de \
--cc=corbet@lwn.net \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jdelvare@suse.com \
--cc=kuurtb@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox