[PATCH v2 1/2] hp-wmi: Modernize hp_wmi_perform_query() to use the modern API
yahia <[email protected]>
| Newsgroups | org.kernel.vger.platform-driver-x86 |
|---|---|
| Message-ID | <[email protected]> |
From: yahia ahmed <[email protected]> hp_wmi_perform_query() currently uses the deprecated wmi_evaluate_method(), Which is depracted and replaced with the modern wmidev_evaluate_method(). Suggested-by: Ilpo Järvinen <[email protected]> Signed-off-by: yahia ahmed <[email protected]> --- v1->v2: -Fix a potential null derefernce highlighted by sashiko -Fix a typo in the unregisteration process --- drivers/platform/x86/hp/hp-wmi.c | 51 ++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c index 8ba286ed8721..5ac29361dc17 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -14,6 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/acpi.h> +#include <linux/wmi.h> #include <linux/cleanup.h> #include <linux/compiler_attributes.h> #include <linux/dmi.h> @@ -506,6 +507,14 @@ struct hp_wmi_hwmon_priv { struct delayed_work keep_alive_dwork; }; +struct wmi_device *hp_wmi_wdev; + +static const struct wmi_device_id hp_wmi_guid_table[] = { + { .guid_string = HPWMI_BIOS_GUID }, + {} +}; +MODULE_DEVICE_TABLE(wmi, hp_wmi_guid_table); + struct victus_s_fan_table_header { u8 num_fans; u8 unknown; @@ -587,6 +596,8 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, size_t bios_args_size; int ret; + if (!hp_wmi_wdev) + return -ENODEV; mid = encode_outsize_for_pvsz(outsize); if (WARN_ON(mid < 0)) return mid; @@ -606,7 +617,7 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, args->datasize = insize; memcpy(args->data, buffer, flex_array_size(args, data, insize)); - ret = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, mid, &input, &output); + ret = wmidev_evaluate_method(hp_wmi_wdev, 0, mid, &input, &output); if (ret) goto out_free; @@ -2717,14 +2728,40 @@ static void __init setup_active_thermal_profile_params(void) } } +static int hp_wmi_probe(struct wmi_device *wdev, const void *context) +{ + hp_wmi_wdev = wdev; + return 0; +} + +static void hp_wmi_remove(struct wmi_device *wdev) +{ + hp_wmi_wdev = NULL; +} + +static struct wmi_driver hp_wmi_wdev_driver = { + .driver = { + .name = "hp-wmi-wdev", + }, + .id_table = hp_wmi_guid_table, + .probe = hp_wmi_probe, + .remove = hp_wmi_remove, +}; + + static int __init hp_wmi_init(void) { int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); int err, tmp = 0; + err = wmi_driver_register(&hp_wmi_wdev_driver); + if (err) + return err; - if (!bios_capable && !event_capable) - return -ENODEV; + if (!bios_capable && !event_capable) { + err = -ENODEV; + goto err_unregister_wmi; + } if (hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &tmp, sizeof(tmp), sizeof(tmp)) == HPWMI_RET_INVALID_PARAMETERS) @@ -2733,7 +2770,7 @@ static int __init hp_wmi_init(void) if (event_capable) { err = hp_wmi_input_setup(); if (err) - return err; + goto err_unregister_wmi; } if (bios_capable) { @@ -2771,7 +2808,8 @@ static int __init hp_wmi_init(void) err_destroy_input: if (event_capable) hp_wmi_input_destroy(); - +err_unregister_wmi: + wmi_driver_unregister(&hp_wmi_wdev_driver); return err; } module_init(hp_wmi_init); @@ -2794,5 +2832,8 @@ static void __exit hp_wmi_exit(void) platform_device_unregister(hp_wmi_platform_dev); platform_driver_unregister(&hp_wmi_driver); } + + if (hp_wmi_wdev) + wmi_driver_unregister(&hp_wmi_wdev_driver); } module_exit(hp_wmi_exit); -- 2.55.0