Skip to content

Commit 5014349

Browse files
Wer-WolfKyleGospo
authored andcommitted
[FROM-ML] platform/x86: msi-wmi-platform: Use input buffer for returning result
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>
1 parent 8cb4944 commit 5014349

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

drivers/platform/x86/msi-wmi-platform.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/mutex.h>
2323
#include <linux/printk.h>
2424
#include <linux/rwsem.h>
25+
#include <linux/string.h>
2526
#include <linux/types.h>
2627
#include <linux/wmi.h>
2728

@@ -141,19 +142,19 @@ static int msi_wmi_platform_parse_buffer(union acpi_object *obj, u8 *output, siz
141142
}
142143

143144
static int msi_wmi_platform_query(struct msi_wmi_platform_data *data,
144-
enum msi_wmi_platform_method method, u8 *input,
145-
size_t input_length, u8 *output, size_t output_length)
145+
enum msi_wmi_platform_method method, u8 *buffer,
146+
size_t length)
146147
{
147148
struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
148149
struct acpi_buffer in = {
149-
.length = input_length,
150-
.pointer = input
150+
.length = length,
151+
.pointer = buffer
151152
};
152153
union acpi_object *obj;
153154
acpi_status status;
154155
int ret;
155156

156-
if (!input_length || !output_length)
157+
if (!length)
157158
return -EINVAL;
158159

159160
/*
@@ -170,7 +171,7 @@ static int msi_wmi_platform_query(struct msi_wmi_platform_data *data,
170171
if (!obj)
171172
return -ENODATA;
172173

173-
ret = msi_wmi_platform_parse_buffer(obj, output, output_length);
174+
ret = msi_wmi_platform_parse_buffer(obj, buffer, length);
174175
kfree(obj);
175176

176177
return ret;
@@ -186,17 +187,15 @@ static int msi_wmi_platform_read(struct device *dev, enum hwmon_sensor_types typ
186187
int channel, long *val)
187188
{
188189
struct msi_wmi_platform_data *data = dev_get_drvdata(dev);
189-
u8 input[32] = { 0 };
190-
u8 output[32];
190+
u8 buffer[32] = { 0 };
191191
u16 value;
192192
int ret;
193193

194-
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_FAN, input, sizeof(input), output,
195-
sizeof(output));
194+
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_FAN, buf, sizeof(buf));
196195
if (ret < 0)
197196
return ret;
198197

199-
value = get_unaligned_be16(&output[channel * 2 + 1]);
198+
value = get_unaligned_be16(&buffer[channel * 2 + 1]);
200199
if (!value)
201200
*val = 0;
202201
else
@@ -246,13 +245,17 @@ static ssize_t msi_wmi_platform_write(struct file *fp, const char __user *input,
246245
return ret;
247246

248247
down_write(&data->buffer_lock);
249-
ret = msi_wmi_platform_query(data->data, data->method, payload, data->length, data->buffer,
248+
ret = msi_wmi_platform_query(data->data, data->method, data->buffer,
250249
data->length);
251250
up_write(&data->buffer_lock);
252251

253252
if (ret < 0)
254253
return ret;
255254

255+
down_write(&data->buffer_lock);
256+
memcpy(data->buffer, payload, data->length);
257+
up_write(&data->buffer_lock);
258+
256259
return length;
257260
}
258261

@@ -349,23 +352,21 @@ static int msi_wmi_platform_hwmon_init(struct msi_wmi_platform_data *data)
349352

350353
static int msi_wmi_platform_ec_init(struct msi_wmi_platform_data *data)
351354
{
352-
u8 input[32] = { 0 };
353-
u8 output[32];
355+
u8 buffer[32] = { 0 };
354356
u8 flags;
355357
int ret;
356358

357-
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_EC, input, sizeof(input), output,
358-
sizeof(output));
359+
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_EC, buffer, sizeof(buffer));
359360
if (ret < 0)
360361
return ret;
361362

362-
flags = output[MSI_PLATFORM_EC_FLAGS_OFFSET];
363+
flags = buffer[MSI_PLATFORM_EC_FLAGS_OFFSET];
363364

364365
dev_dbg(&data->wdev->dev, "EC RAM version %lu.%lu\n",
365366
FIELD_GET(MSI_PLATFORM_EC_MAJOR_MASK, flags),
366367
FIELD_GET(MSI_PLATFORM_EC_MINOR_MASK, flags));
367368
dev_dbg(&data->wdev->dev, "EC firmware version %.28s\n",
368-
&output[MSI_PLATFORM_EC_VERSION_OFFSET]);
369+
&buffer[MSI_PLATFORM_EC_VERSION_OFFSET]);
369370

370371
if (!(flags & MSI_PLATFORM_EC_IS_TIGERLAKE)) {
371372
if (!force)
@@ -379,27 +380,25 @@ static int msi_wmi_platform_ec_init(struct msi_wmi_platform_data *data)
379380

380381
static int msi_wmi_platform_init(struct msi_wmi_platform_data *data)
381382
{
382-
u8 input[32] = { 0 };
383-
u8 output[32];
383+
u8 buffer[32] = { 0 };
384384
int ret;
385385

386-
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_WMI, input, sizeof(input), output,
387-
sizeof(output));
386+
ret = msi_wmi_platform_query(data, MSI_PLATFORM_GET_WMI, buffer, sizeof(buffer));
388387
if (ret < 0)
389388
return ret;
390389

391390
dev_dbg(&data->wdev->dev, "WMI interface version %u.%u\n",
392-
output[MSI_PLATFORM_WMI_MAJOR_OFFSET],
393-
output[MSI_PLATFORM_WMI_MINOR_OFFSET]);
391+
buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET],
392+
buffer[MSI_PLATFORM_WMI_MINOR_OFFSET]);
394393

395-
if (output[MSI_PLATFORM_WMI_MAJOR_OFFSET] != MSI_WMI_PLATFORM_INTERFACE_VERSION) {
394+
if (buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET] != MSI_WMI_PLATFORM_INTERFACE_VERSION) {
396395
if (!force)
397396
return -ENODEV;
398397

399398
dev_warn(&data->wdev->dev,
400399
"Loading despite unsupported WMI interface version (%u.%u)\n",
401-
output[MSI_PLATFORM_WMI_MAJOR_OFFSET],
402-
output[MSI_PLATFORM_WMI_MINOR_OFFSET]);
400+
buffer[MSI_PLATFORM_WMI_MAJOR_OFFSET],
401+
buffer[MSI_PLATFORM_WMI_MINOR_OFFSET]);
403402
}
404403

405404
return 0;

0 commit comments

Comments
 (0)