linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] hp-wmi: Fix dock status and tablet mode reporting
@ 2017-04-19 17:41 Carlo Caione
  2017-04-19 17:41 ` [PATCH v2 1/2] hp-wmi: Do not shadow error values Carlo Caione
  2017-04-19 17:41 ` [PATCH v2 2/2] hp-wmi: Fix detection for dock and tablet mode Carlo Caione
  0 siblings, 2 replies; 5+ messages in thread
From: Carlo Caione @ 2017-04-19 17:41 UTC (permalink / raw)
  To: dvhart, andy, andy.shevchenko, platform-driver-x86, linux-kernel, linux
  Cc: Carlo Caione

From: Carlo Caione <carlo@endlessm.com>

Several HP laptops cannot be put to sleep using the LID since systemd complains
that the system is docked even though the laptop is not even dockable (see
[1]).

This is due to a bug in hp-wmi where the driver is failing to check for errors
before creating the input switches.

[1]: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1574120

changelog:

v2:
 * Changed PATCH 1/2 to not shadow negative errors if any

Carlo Caione (2):
  hp-wmi: Do not shadow error values
  hp-wmi: Fix detection for dock and tablet mode

 drivers/platform/x86/hp-wmi.c | 52 +++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 19 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] hp-wmi: Do not shadow error values
  2017-04-19 17:41 [PATCH v2 0/2] hp-wmi: Fix dock status and tablet mode reporting Carlo Caione
@ 2017-04-19 17:41 ` Carlo Caione
  2017-04-19 20:11   ` Darren Hart
  2017-04-19 17:41 ` [PATCH v2 2/2] hp-wmi: Fix detection for dock and tablet mode Carlo Caione
  1 sibling, 1 reply; 5+ messages in thread
From: Carlo Caione @ 2017-04-19 17:41 UTC (permalink / raw)
  To: dvhart, andy, andy.shevchenko, platform-driver-x86, linux-kernel, linux
  Cc: Carlo Caione

From: Carlo Caione <carlo@endlessm.com>

All the helper functions (i.e. hp_wmi_dock_state, hp_wmi_tablet_state,
...) using hp_wmi_perform_query to perform an HP WMI query shadow the
returned value in case of error.

We return -EINVAL only when the HP WMI query returns a positive value
(the specific error code) to not mix this up with the actual value
returned by the helper function.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 drivers/platform/x86/hp-wmi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 96ffda4..8c7773a 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -248,7 +248,7 @@ static int hp_wmi_display_state(void)
 	int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state,
 				       sizeof(state), sizeof(state));
 	if (ret)
-		return -EINVAL;
+		return ret < 0 ? ret : -EINVAL;
 	return state;
 }
 
@@ -258,7 +258,7 @@ static int hp_wmi_hddtemp_state(void)
 	int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state,
 				       sizeof(state), sizeof(state));
 	if (ret)
-		return -EINVAL;
+		return ret < 0 ? ret : -EINVAL;
 	return state;
 }
 
@@ -268,7 +268,7 @@ static int hp_wmi_als_state(void)
 	int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state,
 				       sizeof(state), sizeof(state));
 	if (ret)
-		return -EINVAL;
+		return ret < 0 ? ret : -EINVAL;
 	return state;
 }
 
@@ -279,7 +279,7 @@ static int hp_wmi_dock_state(void)
 				       sizeof(state), sizeof(state));
 
 	if (ret)
-		return -EINVAL;
+		return ret < 0 ? ret : -EINVAL;
 
 	return state & 0x1;
 }
@@ -290,7 +290,7 @@ static int hp_wmi_tablet_state(void)
 	int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
 				       sizeof(state), sizeof(state));
 	if (ret)
-		return ret;
+		return ret < 0 ? ret : -EINVAL;
 
 	return (state & 0x4) ? 1 : 0;
 }
@@ -323,7 +323,7 @@ static int __init hp_wmi_enable_hotkeys(void)
 	int ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, 1, &value,
 				       sizeof(value), 0);
 	if (ret)
-		return -EINVAL;
+		return ret < 0 ? ret : -EINVAL;
 	return 0;
 }
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] hp-wmi: Fix detection for dock and tablet mode
  2017-04-19 17:41 [PATCH v2 0/2] hp-wmi: Fix dock status and tablet mode reporting Carlo Caione
  2017-04-19 17:41 ` [PATCH v2 1/2] hp-wmi: Do not shadow error values Carlo Caione
@ 2017-04-19 17:41 ` Carlo Caione
  1 sibling, 0 replies; 5+ messages in thread
From: Carlo Caione @ 2017-04-19 17:41 UTC (permalink / raw)
  To: dvhart, andy, andy.shevchenko, platform-driver-x86, linux-kernel, linux
  Cc: Carlo Caione

From: Carlo Caione <carlo@endlessm.com>

The current driver code is not checking for the error values returned by
'hp_wmi_dock_state()' and 'hp_wmi_tablet_state()' before passing the
returned values down to 'input_report_switch()'. This error code is
being translated to '1' in the input subsystem, reporting the wrong
status.

The biggest problem caused by this issue is that several laptops are
wrongly reported by the driver as docked, preventing them to be put to
sleep using the LID (and in most cases they are not even dockable).

With this patch we create the report switches only if we are able to
read the dock and tablet mode status correctly from ACPI.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 drivers/platform/x86/hp-wmi.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 8c7773a..95fab81 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -572,10 +572,12 @@ static void hp_wmi_notify(u32 value, void *context)
 
 	switch (event_id) {
 	case HPWMI_DOCK_EVENT:
-		input_report_switch(hp_wmi_input_dev, SW_DOCK,
-				    hp_wmi_dock_state());
-		input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
-				    hp_wmi_tablet_state());
+		if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
+			input_report_switch(hp_wmi_input_dev, SW_DOCK,
+					    hp_wmi_dock_state());
+		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
+			input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
+					    hp_wmi_tablet_state());
 		input_sync(hp_wmi_input_dev);
 		break;
 	case HPWMI_PARK_HDD:
@@ -644,6 +646,7 @@ static int __init hp_wmi_input_setup(void)
 {
 	acpi_status status;
 	int err;
+	int val;
 
 	hp_wmi_input_dev = input_allocate_device();
 	if (!hp_wmi_input_dev)
@@ -654,17 +657,26 @@ static int __init hp_wmi_input_setup(void)
 	hp_wmi_input_dev->id.bustype = BUS_HOST;
 
 	__set_bit(EV_SW, hp_wmi_input_dev->evbit);
-	__set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
-	__set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
+
+	/* Dock */
+	val = hp_wmi_dock_state();
+	if (!(val < 0)) {
+		__set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
+		input_report_switch(hp_wmi_input_dev, SW_DOCK, val);
+	}
+
+	/* Tablet mode */
+	val = hp_wmi_tablet_state();
+	if (!(val < 0)) {
+		__set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
+		input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val);
+	}
 
 	err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
 	if (err)
 		goto err_free_dev;
 
 	/* Set initial hardware state */
-	input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
-	input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
-			    hp_wmi_tablet_state());
 	input_sync(hp_wmi_input_dev);
 
 	if (!hp_wmi_bios_2009_later() && hp_wmi_bios_2008_later())
@@ -950,10 +962,12 @@ static int hp_wmi_resume_handler(struct device *device)
 	 * changed.
 	 */
 	if (hp_wmi_input_dev) {
-		input_report_switch(hp_wmi_input_dev, SW_DOCK,
-				    hp_wmi_dock_state());
-		input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
-				    hp_wmi_tablet_state());
+		if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
+			input_report_switch(hp_wmi_input_dev, SW_DOCK,
+					    hp_wmi_dock_state());
+		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
+			input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
+					    hp_wmi_tablet_state());
 		input_sync(hp_wmi_input_dev);
 	}
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] hp-wmi: Do not shadow error values
  2017-04-19 17:41 ` [PATCH v2 1/2] hp-wmi: Do not shadow error values Carlo Caione
@ 2017-04-19 20:11   ` Darren Hart
  2017-04-19 20:25     ` Carlo Caione
  0 siblings, 1 reply; 5+ messages in thread
From: Darren Hart @ 2017-04-19 20:11 UTC (permalink / raw)
  To: Carlo Caione
  Cc: andy, andy.shevchenko, platform-driver-x86, linux-kernel, linux,
	Carlo Caione

On Wed, Apr 19, 2017 at 07:41:53PM +0200, Carlo Caione wrote:
> From: Carlo Caione <carlo@endlessm.com>
> 
> All the helper functions (i.e. hp_wmi_dock_state, hp_wmi_tablet_state,
> ...) using hp_wmi_perform_query to perform an HP WMI query shadow the
> returned value in case of error.
> 
> We return -EINVAL only when the HP WMI query returns a positive value
> (the specific error code) to not mix this up with the actual value
> returned by the helper function.

So Andy is correct in that we try to avoid shadowing error codes where possible.
I accepted v1 of this series because it fixed an existing problem in a way
consistent with the existing code.

Since v1 is already in for-next, let's consider the following a subsequent
cleanup. Would you please create a new patch to address the shadowing error code
issues on top of the v1 patch series.

Thanks,
-- 
Darren Hart
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] hp-wmi: Do not shadow error values
  2017-04-19 20:11   ` Darren Hart
@ 2017-04-19 20:25     ` Carlo Caione
  0 siblings, 0 replies; 5+ messages in thread
From: Carlo Caione @ 2017-04-19 20:25 UTC (permalink / raw)
  To: Darren Hart
  Cc: Carlo Caione, Andy Shevchenko, Andy Shevchenko, Platform Driver,
	linux-kernel, Linux Upstreaming Team

On Wed, Apr 19, 2017 at 10:11 PM, Darren Hart <dvhart@infradead.org> wrote:
> On Wed, Apr 19, 2017 at 07:41:53PM +0200, Carlo Caione wrote:
>> From: Carlo Caione <carlo@endlessm.com>
>>
>> All the helper functions (i.e. hp_wmi_dock_state, hp_wmi_tablet_state,
>> ...) using hp_wmi_perform_query to perform an HP WMI query shadow the
>> returned value in case of error.
>>
>> We return -EINVAL only when the HP WMI query returns a positive value
>> (the specific error code) to not mix this up with the actual value
>> returned by the helper function.
>
> So Andy is correct in that we try to avoid shadowing error codes where possible.
> I accepted v1 of this series because it fixed an existing problem in a way
> consistent with the existing code.
>
> Since v1 is already in for-next, let's consider the following a subsequent
> cleanup. Would you please create a new patch to address the shadowing error code
> issues on top of the v1 patch series.

No problem. On its way.

-- 
Carlo Caione  |  +39.340.80.30.096  |  Endless

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-19 20:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 17:41 [PATCH v2 0/2] hp-wmi: Fix dock status and tablet mode reporting Carlo Caione
2017-04-19 17:41 ` [PATCH v2 1/2] hp-wmi: Do not shadow error values Carlo Caione
2017-04-19 20:11   ` Darren Hart
2017-04-19 20:25     ` Carlo Caione
2017-04-19 17:41 ` [PATCH v2 2/2] hp-wmi: Fix detection for dock and tablet mode Carlo Caione

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).