Commit e04e2b76 authored by Armin Wolf's avatar Armin Wolf Committed by Hans de Goede

platform/x86: wmi: Pass event data directly to legacy notify handlers

The current legacy WMI handlers are susceptible to picking up wrong
WMI event data on systems where different WMI devices share some
notification IDs.

Prevent this by letting the WMI driver core taking care of retrieving
the event data. This also simplifies the legacy WMI handlers and their
implementation inside the WMI driver core.
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarArmin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20240901031055.3030-3-W_Armin@gmx.deSigned-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 56d8b784
...@@ -1597,15 +1597,13 @@ static void hp_wmi_devm_notify_remove(void *ignored) ...@@ -1597,15 +1597,13 @@ static void hp_wmi_devm_notify_remove(void *ignored)
} }
/* hp_wmi_notify - WMI event notification handler */ /* hp_wmi_notify - WMI event notification handler */
static void hp_wmi_notify(u32 value, void *context) static void hp_wmi_notify(union acpi_object *wobj, void *context)
{ {
struct hp_wmi_info *temp_info[HP_WMI_MAX_INSTANCES] = {}; struct hp_wmi_info *temp_info[HP_WMI_MAX_INSTANCES] = {};
struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
struct hp_wmi_sensors *state = context; struct hp_wmi_sensors *state = context;
struct device *dev = &state->wdev->dev; struct device *dev = &state->wdev->dev;
struct hp_wmi_event event = {}; struct hp_wmi_event event = {};
struct hp_wmi_info *fan_info; struct hp_wmi_info *fan_info;
union acpi_object *wobj;
acpi_status err; acpi_status err;
int event_type; int event_type;
u8 count; u8 count;
...@@ -1630,20 +1628,15 @@ static void hp_wmi_notify(u32 value, void *context) ...@@ -1630,20 +1628,15 @@ static void hp_wmi_notify(u32 value, void *context)
* HPBIOS_BIOSEvent instance. * HPBIOS_BIOSEvent instance.
*/ */
mutex_lock(&state->lock);
err = wmi_get_event_data(value, &out);
if (ACPI_FAILURE(err))
goto out_unlock;
wobj = out.pointer;
if (!wobj) if (!wobj)
goto out_unlock; return;
mutex_lock(&state->lock);
err = populate_event_from_wobj(dev, &event, wobj); err = populate_event_from_wobj(dev, &event, wobj);
if (err) { if (err) {
dev_warn(dev, "Bad event data (ACPI type %d)\n", wobj->type); dev_warn(dev, "Bad event data (ACPI type %d)\n", wobj->type);
goto out_free_wobj; goto out_free;
} }
event_type = classify_event(event.name, event.category); event_type = classify_event(event.name, event.category);
...@@ -1668,13 +1661,10 @@ static void hp_wmi_notify(u32 value, void *context) ...@@ -1668,13 +1661,10 @@ static void hp_wmi_notify(u32 value, void *context)
break; break;
} }
out_free_wobj: out_free:
kfree(wobj);
devm_kfree(dev, event.name); devm_kfree(dev, event.name);
devm_kfree(dev, event.description); devm_kfree(dev, event.description);
out_unlock:
mutex_unlock(&state->lock); mutex_unlock(&state->lock);
} }
......
...@@ -2223,39 +2223,25 @@ static void acer_rfkill_exit(void) ...@@ -2223,39 +2223,25 @@ static void acer_rfkill_exit(void)
} }
} }
static void acer_wmi_notify(u32 value, void *context) static void acer_wmi_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
struct event_return_value return_value; struct event_return_value return_value;
acpi_status status;
u16 device_state; u16 device_state;
const struct key_entry *key; const struct key_entry *key;
u32 scancode; u32 scancode;
status = wmi_get_event_data(value, &response);
if (status != AE_OK) {
pr_warn("bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (!obj) if (!obj)
return; return;
if (obj->type != ACPI_TYPE_BUFFER) { if (obj->type != ACPI_TYPE_BUFFER) {
pr_warn("Unknown response received %d\n", obj->type); pr_warn("Unknown response received %d\n", obj->type);
kfree(obj);
return; return;
} }
if (obj->buffer.length != 8) { if (obj->buffer.length != 8) {
pr_warn("Unknown buffer length %d\n", obj->buffer.length); pr_warn("Unknown buffer length %d\n", obj->buffer.length);
kfree(obj);
return; return;
} }
return_value = *((struct event_return_value *)obj->buffer.pointer); return_value = *((struct event_return_value *)obj->buffer.pointer);
kfree(obj);
switch (return_value.function) { switch (return_value.function) {
case WMID_HOTKEY_EVENT: case WMID_HOTKEY_EVENT:
......
...@@ -4201,28 +4201,15 @@ static void asus_wmi_fnlock_update(struct asus_wmi *asus) ...@@ -4201,28 +4201,15 @@ static void asus_wmi_fnlock_update(struct asus_wmi *asus)
/* WMI events *****************************************************************/ /* WMI events *****************************************************************/
static int asus_wmi_get_event_code(u32 value) static int asus_wmi_get_event_code(union acpi_object *obj)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
acpi_status status;
int code; int code;
status = wmi_get_event_data(value, &response);
if (ACPI_FAILURE(status)) {
pr_warn("Failed to get WMI notify code: %s\n",
acpi_format_exception(status));
return -EIO;
}
obj = (union acpi_object *)response.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) if (obj && obj->type == ACPI_TYPE_INTEGER)
code = (int)(obj->integer.value & WMI_EVENT_MASK); code = (int)(obj->integer.value & WMI_EVENT_MASK);
else else
code = -EIO; code = -EIO;
kfree(obj);
return code; return code;
} }
...@@ -4288,10 +4275,10 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) ...@@ -4288,10 +4275,10 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
pr_info("Unknown key code 0x%x\n", code); pr_info("Unknown key code 0x%x\n", code);
} }
static void asus_wmi_notify(u32 value, void *context) static void asus_wmi_notify(union acpi_object *obj, void *context)
{ {
struct asus_wmi *asus = context; struct asus_wmi *asus = context;
int code = asus_wmi_get_event_code(value); int code = asus_wmi_get_event_code(obj);
if (code < 0) { if (code < 0) {
pr_warn("Failed to get notify code: %d\n", code); pr_warn("Failed to get notify code: %d\n", code);
......
...@@ -70,20 +70,10 @@ static bool dell_wmi_aio_event_check(u8 *buffer, int length) ...@@ -70,20 +70,10 @@ static bool dell_wmi_aio_event_check(u8 *buffer, int length)
return false; return false;
} }
static void dell_wmi_aio_notify(u32 value, void *context) static void dell_wmi_aio_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
struct dell_wmi_event *event; struct dell_wmi_event *event;
acpi_status status;
status = wmi_get_event_data(value, &response);
if (status != AE_OK) {
pr_info("bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (obj) { if (obj) {
unsigned int scancode = 0; unsigned int scancode = 0;
...@@ -114,7 +104,6 @@ static void dell_wmi_aio_notify(u32 value, void *context) ...@@ -114,7 +104,6 @@ static void dell_wmi_aio_notify(u32 value, void *context)
break; break;
} }
} }
kfree(obj);
} }
static int __init dell_wmi_aio_input_setup(void) static int __init dell_wmi_aio_input_setup(void)
......
...@@ -834,28 +834,16 @@ static struct attribute *hp_wmi_attrs[] = { ...@@ -834,28 +834,16 @@ static struct attribute *hp_wmi_attrs[] = {
}; };
ATTRIBUTE_GROUPS(hp_wmi); ATTRIBUTE_GROUPS(hp_wmi);
static void hp_wmi_notify(u32 value, void *context) static void hp_wmi_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
u32 event_id, event_data; u32 event_id, event_data;
union acpi_object *obj;
acpi_status status;
u32 *location; u32 *location;
int key_code; int key_code;
status = wmi_get_event_data(value, &response);
if (status != AE_OK) {
pr_info("bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (!obj) if (!obj)
return; return;
if (obj->type != ACPI_TYPE_BUFFER) { if (obj->type != ACPI_TYPE_BUFFER) {
pr_info("Unknown response received %d\n", obj->type); pr_info("Unknown response received %d\n", obj->type);
kfree(obj);
return; return;
} }
...@@ -872,10 +860,8 @@ static void hp_wmi_notify(u32 value, void *context) ...@@ -872,10 +860,8 @@ static void hp_wmi_notify(u32 value, void *context)
event_data = *(location + 2); event_data = *(location + 2);
} else { } else {
pr_info("Unknown buffer length %d\n", obj->buffer.length); pr_info("Unknown buffer length %d\n", obj->buffer.length);
kfree(obj);
return; return;
} }
kfree(obj);
switch (event_id) { switch (event_id) {
case HPWMI_DOCK_EVENT: case HPWMI_DOCK_EVENT:
......
...@@ -734,26 +734,14 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code) ...@@ -734,26 +734,14 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code)
sparse_keymap_report_entry(idev, key, 1, true); sparse_keymap_report_entry(idev, key, 1, true);
} }
static void huawei_wmi_input_notify(u32 value, void *context) static void huawei_wmi_input_notify(union acpi_object *obj, void *context)
{ {
struct input_dev *idev = (struct input_dev *)context; struct input_dev *idev = (struct input_dev *)context;
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
acpi_status status;
status = wmi_get_event_data(value, &response);
if (ACPI_FAILURE(status)) {
dev_err(&idev->dev, "Unable to get event data\n");
return;
}
obj = (union acpi_object *)response.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) if (obj && obj->type == ACPI_TYPE_INTEGER)
huawei_wmi_process_key(idev, obj->integer.value); huawei_wmi_process_key(idev, obj->integer.value);
else else
dev_err(&idev->dev, "Bad response type\n"); dev_err(&idev->dev, "Bad response type\n");
kfree(response.pointer);
} }
static int huawei_wmi_input_setup(struct device *dev, const char *guid) static int huawei_wmi_input_setup(struct device *dev, const char *guid)
......
...@@ -205,21 +205,11 @@ static union acpi_object *lg_wmbb(struct device *dev, u32 method_id, u32 arg1, u ...@@ -205,21 +205,11 @@ static union acpi_object *lg_wmbb(struct device *dev, u32 method_id, u32 arg1, u
return (union acpi_object *)buffer.pointer; return (union acpi_object *)buffer.pointer;
} }
static void wmi_notify(u32 value, void *context) static void wmi_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
acpi_status status;
long data = (long)context; long data = (long)context;
pr_debug("event guid %li\n", data); pr_debug("event guid %li\n", data);
status = wmi_get_event_data(value, &response);
if (ACPI_FAILURE(status)) {
pr_err("Bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (!obj) if (!obj)
return; return;
...@@ -241,7 +231,6 @@ static void wmi_notify(u32 value, void *context) ...@@ -241,7 +231,6 @@ static void wmi_notify(u32 value, void *context)
pr_debug("Type: %i Eventcode: 0x%llx\n", obj->type, pr_debug("Type: %i Eventcode: 0x%llx\n", obj->type,
obj->integer.value); obj->integer.value);
kfree(response.pointer);
} }
static void wmi_input_setup(void) static void wmi_input_setup(void)
......
...@@ -170,20 +170,9 @@ static const struct backlight_ops msi_backlight_ops = { ...@@ -170,20 +170,9 @@ static const struct backlight_ops msi_backlight_ops = {
.update_status = bl_set_status, .update_status = bl_set_status,
}; };
static void msi_wmi_notify(u32 value, void *context) static void msi_wmi_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
struct key_entry *key; struct key_entry *key;
union acpi_object *obj;
acpi_status status;
status = wmi_get_event_data(value, &response);
if (status != AE_OK) {
pr_info("bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) { if (obj && obj->type == ACPI_TYPE_INTEGER) {
int eventcode = obj->integer.value; int eventcode = obj->integer.value;
...@@ -192,7 +181,7 @@ static void msi_wmi_notify(u32 value, void *context) ...@@ -192,7 +181,7 @@ static void msi_wmi_notify(u32 value, void *context)
eventcode); eventcode);
if (!key) { if (!key) {
pr_info("Unknown key pressed - %x\n", eventcode); pr_info("Unknown key pressed - %x\n", eventcode);
goto msi_wmi_notify_exit; return;
} }
if (event_wmi->quirk_last_pressed) { if (event_wmi->quirk_last_pressed) {
...@@ -204,7 +193,7 @@ static void msi_wmi_notify(u32 value, void *context) ...@@ -204,7 +193,7 @@ static void msi_wmi_notify(u32 value, void *context)
pr_debug("Suppressed key event 0x%X - " pr_debug("Suppressed key event 0x%X - "
"Last press was %lld us ago\n", "Last press was %lld us ago\n",
key->code, ktime_to_us(diff)); key->code, ktime_to_us(diff));
goto msi_wmi_notify_exit; return;
} }
last_pressed = cur; last_pressed = cur;
} }
...@@ -221,9 +210,6 @@ static void msi_wmi_notify(u32 value, void *context) ...@@ -221,9 +210,6 @@ static void msi_wmi_notify(u32 value, void *context)
} }
} else } else
pr_info("Unknown event received\n"); pr_info("Unknown event received\n");
msi_wmi_notify_exit:
kfree(response.pointer);
} }
static int __init msi_wmi_backlight_setup(void) static int __init msi_wmi_backlight_setup(void)
......
...@@ -32,26 +32,13 @@ static const struct key_entry toshiba_wmi_keymap[] __initconst = { ...@@ -32,26 +32,13 @@ static const struct key_entry toshiba_wmi_keymap[] __initconst = {
{ KE_END, 0 } { KE_END, 0 }
}; };
static void toshiba_wmi_notify(u32 value, void *context) static void toshiba_wmi_notify(union acpi_object *obj, void *context)
{ {
struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
acpi_status status;
status = wmi_get_event_data(value, &response);
if (ACPI_FAILURE(status)) {
pr_err("Bad event status 0x%x\n", status);
return;
}
obj = (union acpi_object *)response.pointer;
if (!obj) if (!obj)
return; return;
/* TODO: Add proper checks once we have data */ /* TODO: Add proper checks once we have data */
pr_debug("Unknown event received, obj type %x\n", obj->type); pr_debug("Unknown event received, obj type %x\n", obj->type);
kfree(response.pointer);
} }
static const struct dmi_system_id toshiba_wmi_dmi_table[] __initconst = { static const struct dmi_system_id toshiba_wmi_dmi_table[] __initconst = {
......
...@@ -1227,20 +1227,6 @@ static int wmi_notify_device(struct device *dev, void *data) ...@@ -1227,20 +1227,6 @@ static int wmi_notify_device(struct device *dev, void *data)
if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event)) if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event))
return 0; return 0;
down_read(&wblock->notify_lock);
/* The WMI driver notify handler conflicts with the legacy WMI handler.
* Because of this the WMI driver notify handler takes precedence.
*/
if (wblock->dev.dev.driver && wblock->driver_ready) {
ret = wmi_get_notify_data(wblock, &obj);
if (ret >= 0) {
wmi_notify_driver(wblock, obj);
kfree(obj);
}
} else {
if (wblock->handler) {
wblock->handler(*event, wblock->handler_data);
} else {
/* The ACPI WMI specification says that _WED should be /* The ACPI WMI specification says that _WED should be
* evaluated every time an notification is received, even * evaluated every time an notification is received, even
* if no consumers are present. * if no consumers are present.
...@@ -1249,18 +1235,25 @@ static int wmi_notify_device(struct device *dev, void *data) ...@@ -1249,18 +1235,25 @@ static int wmi_notify_device(struct device *dev, void *data)
* by using a queue for events which will fill up if the * by using a queue for events which will fill up if the
* WMI driver core stops evaluating _WED due to missing * WMI driver core stops evaluating _WED due to missing
* WMI event consumers. * WMI event consumers.
*
* Because of this we need this seemingly useless call to
* wmi_get_notify_data() which in turn evaluates _WED.
*/ */
ret = wmi_get_notify_data(wblock, &obj); ret = wmi_get_notify_data(wblock, &obj);
if (ret >= 0) if (ret < 0)
kfree(obj); return -EIO;
}
down_read(&wblock->notify_lock);
/* The WMI driver notify handler conflicts with the legacy WMI handler.
* Because of this the WMI driver notify handler takes precedence.
*/
if (wblock->dev.dev.driver && wblock->driver_ready) {
wmi_notify_driver(wblock, obj);
} else {
if (wblock->handler)
wblock->handler(obj, wblock->handler_data);
} }
up_read(&wblock->notify_lock); up_read(&wblock->notify_lock);
kfree(obj);
acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0); acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0);
return -EBUSY; return -EBUSY;
......
...@@ -386,7 +386,7 @@ extern bool acpi_is_pnp_device(struct acpi_device *); ...@@ -386,7 +386,7 @@ extern bool acpi_is_pnp_device(struct acpi_device *);
#if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE) #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
typedef void (*wmi_notify_handler) (u32 value, void *context); typedef void (*wmi_notify_handler) (union acpi_object *data, void *context);
int wmi_instance_count(const char *guid); int wmi_instance_count(const char *guid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment