linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Fix a logic error in wake on connect
@ 2025-04-11 15:14 Mario Limonciello
  2025-04-11 15:20 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Mario Limonciello @ 2025-04-11 15:14 UTC (permalink / raw)
  To: mario.limonciello, andreas.noever, michael.jamet, westeri,
	YehezkelShB, rajat.khandelwal
  Cc: mika.westerberg, linux-usb

From: Mario Limonciello <mario.limonciello@amd.com>

commit a5cfc9d65879c ("thunderbolt: Add wake on connect/disconnect
on USB4 ports") introduced a sysfs file to control wake up policy
for a given USB4 port that defaulted to disabled.

However when testing commit 4bfeea6ec1c02 ("thunderbolt: Use wake
on connect and disconnect over suspend") I found that it was working
even without making changes to the power/wakeup file (which defaults
to disabled). This is because of a logic error doing a bitwise or
of the wake-on-connect flag with device_may_wakeup() which should
have been a logical AND.

Adjust the logic so that policy is only applied when wakeup is
actually enabled.

Fixes: a5cfc9d65879c ("thunderbolt: Add wake on connect/disconnect on USB4 ports")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/thunderbolt/usb4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
index e51d01671d8e7..3e96f1afd4268 100644
--- a/drivers/thunderbolt/usb4.c
+++ b/drivers/thunderbolt/usb4.c
@@ -440,10 +440,10 @@ int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
 			bool configured = val & PORT_CS_19_PC;
 			usb4 = port->usb4;
 
-			if (((flags & TB_WAKE_ON_CONNECT) |
+			if (((flags & TB_WAKE_ON_CONNECT) &&
 			      device_may_wakeup(&usb4->dev)) && !configured)
 				val |= PORT_CS_19_WOC;
-			if (((flags & TB_WAKE_ON_DISCONNECT) |
+			if (((flags & TB_WAKE_ON_DISCONNECT) &&
 			      device_may_wakeup(&usb4->dev)) && configured)
 				val |= PORT_CS_19_WOD;
 			if ((flags & TB_WAKE_ON_USB4) && configured)
-- 
2.43.0


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

end of thread, other threads:[~2025-07-15  5:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 15:14 [PATCH] thunderbolt: Fix a logic error in wake on connect Mario Limonciello
2025-04-11 15:20 ` Greg KH
2025-04-16 12:37 ` Mika Westerberg
2025-04-16 13:27   ` Mario Limonciello
2025-04-16 16:23     ` Mika Westerberg
2025-06-29 17:52 ` [REGRESSION] " Alyssa Ross
2025-06-30 11:32   ` Alyssa Ross
2025-07-06 14:46     ` Mario Limonciello
2025-07-07  7:57       ` Greg Kroah-Hartman
2025-07-14 16:35         ` Mario Limonciello
2025-07-15  5:56           ` Greg Kroah-Hartman

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).