]> git.hungrycats.org Git - linux/commitdiff
platform/x86: hp-wmi: Use zero insize parameter only when supported
authorBedant Patnaik <bedant.patnaik@gmail.com>
Wed, 8 Jun 2022 19:28:43 +0000 (00:58 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 16:41:43 +0000 (18:41 +0200)
[ Upstream commit 65f936f3535950d2643eac5bf34a735a0e428cdd ]

commit be9d73e64957 ("platform/x86: hp-wmi: Fix 0x05 error code reported by
several WMI calls") and commit 12b19f14a21a ("platform/x86: hp-wmi: Fix
hp_wmi_read_int() reporting error (0x05)") cause ACPI BIOS Error (bug):
Attempt to CreateField of length zero (20211217/dsopcode-133) because of
the ACPI method HWMC, which unconditionally creates a Field of
size (insize*8) bits:
CreateField (Arg1, 0x80, (Local5 * 0x08), DAIN)
In cases where args->insize = 0, the Field size is 0, resulting in
an error.

Fix this by using zero insize only if 0x5 error code is returned

Tested on Omen 15 AMD (2020) board ID: 8786.

Fixes: be9d73e64957 ("platform/x86: hp-wmi: Fix 0x05 error code reported by several WMI calls")
Signed-off-by: Bedant Patnaik <bedant.patnaik@gmail.com>
Tested-by: Jorge Lopez <jorge.lopez2@hp.com>
Link: https://lore.kernel.org/r/41be46743d21c78741232a47bbb5f1cdbcc3d21e.camel@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/platform/x86/hp-wmi.c

index 29ae35d15a41174cef08195759acf21c7f1377d1..c573bfd9ab0e5ba0818e0d81c627eb4cf6b1b3d3 100644 (file)
@@ -38,6 +38,7 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
 #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
 #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
 #define HP_OMEN_EC_THERMAL_PROFILE_OFFSET 0x95
+#define zero_if_sup(tmp) (zero_insize_support?0:sizeof(tmp)) // use when zero insize is required
 
 /* DMI board names of devices that should use the omen specific path for
  * thermal profiles.
@@ -200,6 +201,7 @@ static struct input_dev *hp_wmi_input_dev;
 static struct platform_device *hp_wmi_platform_dev;
 static struct platform_profile_handler platform_profile_handler;
 static bool platform_profile_support;
+static bool zero_insize_support;
 
 static struct rfkill *wifi_rfkill;
 static struct rfkill *bluetooth_rfkill;
@@ -347,7 +349,7 @@ static int hp_wmi_read_int(int query)
        int val = 0, ret;
 
        ret = hp_wmi_perform_query(query, HPWMI_READ, &val,
-                                  0, sizeof(val));
+                                  zero_if_sup(val), sizeof(val));
 
        if (ret)
                return ret < 0 ? ret : -EINVAL;
@@ -383,7 +385,8 @@ static int hp_wmi_get_tablet_mode(void)
                return -ENODEV;
 
        ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ,
-                                  system_device_mode, 0, sizeof(system_device_mode));
+                                  system_device_mode, zero_if_sup(system_device_mode),
+                                  sizeof(system_device_mode));
        if (ret < 0)
                return ret;
 
@@ -449,7 +452,7 @@ static int hp_wmi_fan_speed_max_get(void)
        int val = 0, ret;
 
        ret = hp_wmi_perform_query(HPWMI_FAN_SPEED_MAX_GET_QUERY, HPWMI_GM,
-                                  &val, 0, sizeof(val));
+                                  &val, zero_if_sup(val), sizeof(val));
 
        if (ret)
                return ret < 0 ? ret : -EINVAL;
@@ -461,7 +464,7 @@ static int __init hp_wmi_bios_2008_later(void)
 {
        int state = 0;
        int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, HPWMI_READ, &state,
-                                      0, sizeof(state));
+                                      zero_if_sup(state), sizeof(state));
        if (!ret)
                return 1;
 
@@ -472,7 +475,7 @@ static int __init hp_wmi_bios_2009_later(void)
 {
        u8 state[128];
        int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, HPWMI_READ, &state,
-                                      0, sizeof(state));
+                                      zero_if_sup(state), sizeof(state));
        if (!ret)
                return 1;
 
@@ -550,7 +553,7 @@ static int hp_wmi_rfkill2_refresh(void)
        int err, i;
 
        err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
-                                  0, sizeof(state));
+                                  zero_if_sup(state), sizeof(state));
        if (err)
                return err;
 
@@ -952,7 +955,7 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
        int err, i;
 
        err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
-                                  0, sizeof(state));
+                                  zero_if_sup(state), sizeof(state));
        if (err)
                return err < 0 ? err : -EINVAL;
 
@@ -1410,11 +1413,15 @@ 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;
+       int err, tmp = 0;
 
        if (!bios_capable && !event_capable)
                return -ENODEV;
 
+       if (hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &tmp,
+                                sizeof(tmp), sizeof(tmp)) == HPWMI_RET_INVALID_PARAMETERS)
+               zero_insize_support = true;
+
        if (event_capable) {
                err = hp_wmi_input_setup();
                if (err)