linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] xhci cleanups and fixes for usb-next
@ 2022-03-03 10:26 Mathias Nyman
  2022-03-03 10:26 ` [PATCH 1/9] xhci: make xhci_handshake timeout for xhci_reset() adjustable Mathias Nyman
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Hi Greg

One more set of xhci fetures and fixes for usb-next.

In addition to some cleanups there are some fixes that
would be nice to get into 5.18-rc1

All fixes are for old issues, so nothing urgent.

Thanks
-Mathias

Anssi Hannula (2):
  xhci: fix garbage USBSTS being logged in some cases
  xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx()

Henry Lin (1):
  xhci: fix runtime PM imbalance in USB2 resume

Linyu Yuan (5):
  usb: host: xhci: use ffs() in xhci_mem_init()
  usb: host: xhci: fix a comment typo in xhci_mem_init()
  usb: host: xhci: update hci_version operation in xhci_gen_setup()
  usb: host: xhci: add blank line in xhci_halt()
  usb: host: xhci: Remove some unnecessary return value initializations

Mathias Nyman (1):
  xhci: make xhci_handshake timeout for xhci_reset() adjustable

 drivers/usb/host/xhci-hub.c |  5 ++++-
 drivers/usb/host/xhci-mem.c | 10 +++-------
 drivers/usb/host/xhci.c     | 34 +++++++++++++++++-----------------
 drivers/usb/host/xhci.h     | 14 +++++++++++---
 4 files changed, 35 insertions(+), 28 deletions(-)

-- 
2.25.1


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

* [PATCH 1/9] xhci: make xhci_handshake timeout for xhci_reset() adjustable
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 2/9] xhci: fix garbage USBSTS being logged in some cases Mathias Nyman
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman, Sergey Shtylyov, Pavan Kondeti, stable

xhci_reset() timeout was increased from 250ms to 10 seconds in order to
give Renesas 720201 xHC enough time to get ready in probe.

xhci_reset() is called with interrupts disabled in other places, and
waiting for 10 seconds there is not acceptable.

Add a timeout parameter to xhci_reset(), and adjust it back to 250ms
when called from xhci_stop() or xhci_shutdown() where interrupts are
disabled, and successful reset isn't that critical.
This solves issues when deactivating host mode on platforms like SM8450.

For now don't change the timeout if xHC is reset in xhci_resume().
No issues are reported for it, and we need the reset to succeed.
Locking around that reset needs to be revisited later.

Additionally change the signed integer timeout parameter in
xhci_handshake() to a u64 to match the timeout value we pass to
readl_poll_timeout_atomic()

Reported-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Reported-by: Pavan Kondeti <quic_pkondeti@quicinc.com>
Fixes: 22ceac191211 ("xhci: Increase reset timeout for Renesas 720201 host.")
Cc: stable@vger.kernel.org
Tested-by: Pavan Kondeti <quic_pkondeti@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c |  2 +-
 drivers/usb/host/xhci-mem.c |  2 +-
 drivers/usb/host/xhci.c     | 20 +++++++++-----------
 drivers/usb/host/xhci.h     |  7 +++++--
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index df3522dab31b..bb4f01ce90e3 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -762,7 +762,7 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci)
 	}
 	pm_runtime_allow(xhci_to_hcd(xhci)->self.controller);
 	xhci->test_mode = 0;
-	return xhci_reset(xhci);
+	return xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
 }
 
 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index cb70d0b31e08..48114a462908 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2575,7 +2575,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 
 fail:
 	xhci_halt(xhci);
-	xhci_reset(xhci);
+	xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
 	xhci_mem_cleanup(xhci);
 	return -ENOMEM;
 }
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a1c781f70d02..6b32f7e65d4c 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -65,7 +65,7 @@ static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
  * handshake done).  There are two failure modes:  "usec" have passed (major
  * hardware flakeout), or the register reads as all-ones (hardware removed).
  */
-int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
+int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us)
 {
 	u32	result;
 	int	ret;
@@ -73,7 +73,7 @@ int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
 	ret = readl_poll_timeout_atomic(ptr, result,
 					(result & mask) == done ||
 					result == U32_MAX,
-					1, usec);
+					1, timeout_us);
 	if (result == U32_MAX)		/* card removed */
 		return -ENODEV;
 
@@ -162,7 +162,7 @@ int xhci_start(struct xhci_hcd *xhci)
  * Transactions will be terminated immediately, and operational registers
  * will be set to their defaults.
  */
-int xhci_reset(struct xhci_hcd *xhci)
+int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us)
 {
 	u32 command;
 	u32 state;
@@ -195,8 +195,7 @@ int xhci_reset(struct xhci_hcd *xhci)
 	if (xhci->quirks & XHCI_INTEL_HOST)
 		udelay(1000);
 
-	ret = xhci_handshake(&xhci->op_regs->command,
-			CMD_RESET, 0, 10 * 1000 * 1000);
+	ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us);
 	if (ret)
 		return ret;
 
@@ -209,8 +208,7 @@ int xhci_reset(struct xhci_hcd *xhci)
 	 * xHCI cannot write to any doorbells or operational registers other
 	 * than status until the "Controller Not Ready" flag is cleared.
 	 */
-	ret = xhci_handshake(&xhci->op_regs->status,
-			STS_CNR, 0, 10 * 1000 * 1000);
+	ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us);
 
 	xhci->usb2_rhub.bus_state.port_c_suspend = 0;
 	xhci->usb2_rhub.bus_state.suspended_ports = 0;
@@ -731,7 +729,7 @@ static void xhci_stop(struct usb_hcd *hcd)
 	xhci->xhc_state |= XHCI_STATE_HALTED;
 	xhci->cmd_ring_state = CMD_RING_STATE_STOPPED;
 	xhci_halt(xhci);
-	xhci_reset(xhci);
+	xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
 	spin_unlock_irq(&xhci->lock);
 
 	xhci_cleanup_msix(xhci);
@@ -784,7 +782,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
 	xhci_halt(xhci);
 	/* Workaround for spurious wakeups at shutdown with HSW */
 	if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
-		xhci_reset(xhci);
+		xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
 	spin_unlock_irq(&xhci->lock);
 
 	xhci_cleanup_msix(xhci);
@@ -1170,7 +1168,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
 		xhci_dbg(xhci, "Stop HCD\n");
 		xhci_halt(xhci);
 		xhci_zero_64b_regs(xhci);
-		retval = xhci_reset(xhci);
+		retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC);
 		spin_unlock_irq(&xhci->lock);
 		if (retval)
 			return retval;
@@ -5307,7 +5305,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
 
 	xhci_dbg(xhci, "Resetting HCD\n");
 	/* Reset the internal HC memory state and registers. */
-	retval = xhci_reset(xhci);
+	retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC);
 	if (retval)
 		return retval;
 	xhci_dbg(xhci, "Reset complete\n");
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 8a0026ee9524..fce32f8ea9d0 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -229,6 +229,9 @@ struct xhci_op_regs {
 #define CMD_ETE		(1 << 14)
 /* bits 15:31 are reserved (and should be preserved on writes). */
 
+#define XHCI_RESET_LONG_USEC		(10 * 1000 * 1000)
+#define XHCI_RESET_SHORT_USEC		(250 * 1000)
+
 /* IMAN - Interrupt Management Register */
 #define IMAN_IE		(1 << 1)
 #define IMAN_IP		(1 << 0)
@@ -2081,11 +2084,11 @@ void xhci_free_container_ctx(struct xhci_hcd *xhci,
 
 /* xHCI host controller glue */
 typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
-int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec);
+int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us);
 void xhci_quiesce(struct xhci_hcd *xhci);
 int xhci_halt(struct xhci_hcd *xhci);
 int xhci_start(struct xhci_hcd *xhci);
-int xhci_reset(struct xhci_hcd *xhci);
+int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us);
 int xhci_run(struct usb_hcd *hcd);
 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
 void xhci_shutdown(struct usb_hcd *hcd);
-- 
2.25.1


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

* [PATCH 2/9] xhci: fix garbage USBSTS being logged in some cases
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
  2022-03-03 10:26 ` [PATCH 1/9] xhci: make xhci_handshake timeout for xhci_reset() adjustable Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx() Mathias Nyman
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Anssi Hannula, stable, Mathias Nyman

From: Anssi Hannula <anssi.hannula@bitwise.fi>

xhci_decode_usbsts() is expected to return a zero-terminated string by
its only caller, xhci_stop_endpoint_command_watchdog(), which directly
logs the return value:

  xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(str, usbsts));

However, if no recognized bits are set in usbsts, the function will
return without having called any sprintf() and therefore return an
untouched non-zero-terminated caller-provided buffer, causing garbage
to be output to log.

Fix that by always including the raw value in the output.

Note that before commit 4843b4b5ec64 ("xhci: fix even more unsafe memory
usage in xhci tracing") the result effect in the failure case was different
as a static buffer was used here, but the code still worked incorrectly.

Fixes: 9c1aa36efdae ("xhci: Show host status when watchdog triggers and host is assumed dead.")
Cc: stable@vger.kernel.org
Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index fce32f8ea9d0..1d83ddace482 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2625,8 +2625,11 @@ static inline const char *xhci_decode_usbsts(char *str, u32 usbsts)
 {
 	int ret = 0;
 
+	ret = sprintf(str, " 0x%08x", usbsts);
+
 	if (usbsts == ~(u32)0)
-		return " 0xffffffff";
+		return str;
+
 	if (usbsts & STS_HALT)
 		ret += sprintf(str + ret, " HCHalted");
 	if (usbsts & STS_FATAL)
-- 
2.25.1


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

* [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx()
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
  2022-03-03 10:26 ` [PATCH 1/9] xhci: make xhci_handshake timeout for xhci_reset() adjustable Mathias Nyman
  2022-03-03 10:26 ` [PATCH 2/9] xhci: fix garbage USBSTS being logged in some cases Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:43   ` Anssi Hannula
  2022-03-03 10:26 ` [PATCH 4/9] xhci: fix runtime PM imbalance in USB2 resume Mathias Nyman
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Anssi Hannula, stable, Mathias Nyman

From: Anssi Hannula <anssi.hannula@bitwise.fi>

xhci_decode_ctrl_ctx() returns the untouched buffer as-is if both "drop"
and "add" parameters are zero.

Fix the function to return an empty string in that case.

It was not immediately clear from the possible call chains whether this
issue is currently actually triggerable or not.

Note that before commit 4843b4b5ec64 ("xhci: fix even more unsafe memory
Cc: stable@vger.kernel.org
usage in xhci tracing") the result effect in the failure case was different
as a static buffer was used here, but the code still worked incorrectly.

Fixes: 90d6d5731da7 ("xhci: Add tracing for input control context")
Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>

commit 4843b4b5ec64 ("xhci: fix even more unsafe memory usage in xhci tracing")
---
 drivers/usb/host/xhci.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 1d83ddace482..473a33ce299e 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2468,6 +2468,8 @@ static inline const char *xhci_decode_ctrl_ctx(char *str,
 	unsigned int	bit;
 	int		ret = 0;
 
+	str[0] = '\0';
+
 	if (drop) {
 		ret = sprintf(str, "Drop:");
 		for_each_set_bit(bit, &drop, 32)
-- 
2.25.1


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

* [PATCH 4/9] xhci: fix runtime PM imbalance in USB2 resume
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (2 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx() Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 5/9] usb: host: xhci: use ffs() in xhci_mem_init() Mathias Nyman
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Henry Lin, stable, Mathias Nyman

From: Henry Lin <henryl@nvidia.com>

A race between system resume and device-initiated resume may result in
runtime PM imbalance on USB2 root hub. If a device-initiated resume
starts and system resume xhci_bus_resume() directs U0 before hub driver
sees the resuming device in RESUME state, device-initiated resume will
not be finished in xhci_handle_usb2_port_link_resume(). In this case,
usb_hcd_end_port_resume() call is missing.

This changes calls usb_hcd_end_port_resume() if resuming device reaches
U0 to keep runtime PM balance.

Fixes: a231ec41e6f6 ("xhci: refactor U0 link state handling in get_port_status")
Cc: stable@vger.kernel.org
Signed-off-by: Henry Lin <henryl@nvidia.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index bb4f01ce90e3..1e7dc130c39a 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1088,6 +1088,9 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
 		if (link_state == XDEV_U2)
 			*status |= USB_PORT_STAT_L1;
 		if (link_state == XDEV_U0) {
+			if (bus_state->resume_done[portnum])
+				usb_hcd_end_port_resume(&port->rhub->hcd->self,
+							portnum);
 			bus_state->resume_done[portnum] = 0;
 			clear_bit(portnum, &bus_state->resuming_ports);
 			if (bus_state->suspended_ports & (1 << portnum)) {
-- 
2.25.1


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

* [PATCH 5/9] usb: host: xhci: use ffs() in xhci_mem_init()
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (3 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 4/9] xhci: fix runtime PM imbalance in USB2 resume Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 6/9] usb: host: xhci: fix a comment typo " Mathias Nyman
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Linyu Yuan, Mathias Nyman

From: Linyu Yuan <quic_linyyuan@quicinc.com>

The for loop to find page size bit can be replaced with ffs().

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 48114a462908..938eb2b907ab 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2391,11 +2391,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	page_size = readl(&xhci->op_regs->page_size);
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Supported page size register = 0x%x", page_size);
-	for (i = 0; i < 16; i++) {
-		if ((0x1 & page_size) != 0)
-			break;
-		page_size = page_size >> 1;
-	}
+	i = ffs(page_size);
 	if (i < 16)
 		xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Supported page size of %iK", (1 << (i+12)) / 1024);
-- 
2.25.1


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

* [PATCH 6/9] usb: host: xhci: fix a comment typo in xhci_mem_init()
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (4 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 5/9] usb: host: xhci: use ffs() in xhci_mem_init() Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 7/9] usb: host: xhci: update hci_version operation in xhci_gen_setup() Mathias Nyman
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Linyu Yuan, Mathias Nyman

From: Linyu Yuan <quic_linyyuan@quicinc.com>

It should be Device Context, not doorbell.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 938eb2b907ab..bbb27ee2c6a3 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2417,7 +2417,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	writel(val, &xhci->op_regs->config_reg);
 
 	/*
-	 * xHCI section 5.4.6 - doorbell array must be
+	 * xHCI section 5.4.6 - Device Context array must be
 	 * "physically contiguous and 64-byte (cache line) aligned".
 	 */
 	xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma,
-- 
2.25.1


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

* [PATCH 7/9] usb: host: xhci: update hci_version operation in xhci_gen_setup()
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (5 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 6/9] usb: host: xhci: fix a comment typo " Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 8/9] usb: host: xhci: add blank line in xhci_halt() Mathias Nyman
  2022-03-03 10:26 ` [PATCH 9/9] usb: host: xhci: Remove some unnecessary return value initializations Mathias Nyman
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Linyu Yuan, Mathias Nyman

From: Linyu Yuan <quic_linyyuan@quicinc.com>

There is no need to store temperary value in hcc_params.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6b32f7e65d4c..e17eef88e5d7 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -5279,8 +5279,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
 	xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1);
 	xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2);
 	xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3);
-	xhci->hcc_params = readl(&xhci->cap_regs->hc_capbase);
-	xhci->hci_version = HC_VERSION(xhci->hcc_params);
+	xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase));
 	xhci->hcc_params = readl(&xhci->cap_regs->hcc_params);
 	if (xhci->hci_version > 0x100)
 		xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2);
-- 
2.25.1


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

* [PATCH 8/9] usb: host: xhci: add blank line in xhci_halt()
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (6 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 7/9] usb: host: xhci: update hci_version operation in xhci_gen_setup() Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  2022-03-03 10:26 ` [PATCH 9/9] usb: host: xhci: Remove some unnecessary return value initializations Mathias Nyman
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Linyu Yuan, Mathias Nyman

From: Linyu Yuan <quic_linyyuan@quicinc.com>

It is more readable to add blank lines.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index e17eef88e5d7..1aa10db23fbb 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -110,6 +110,7 @@ void xhci_quiesce(struct xhci_hcd *xhci)
 int xhci_halt(struct xhci_hcd *xhci)
 {
 	int ret;
+
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC");
 	xhci_quiesce(xhci);
 
@@ -119,8 +120,10 @@ int xhci_halt(struct xhci_hcd *xhci)
 		xhci_warn(xhci, "Host halt failed, %d\n", ret);
 		return ret;
 	}
+
 	xhci->xhc_state |= XHCI_STATE_HALTED;
 	xhci->cmd_ring_state = CMD_RING_STATE_STOPPED;
+
 	return ret;
 }
 
-- 
2.25.1


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

* [PATCH 9/9] usb: host: xhci: Remove some unnecessary return value initializations
  2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
                   ` (7 preceding siblings ...)
  2022-03-03 10:26 ` [PATCH 8/9] usb: host: xhci: add blank line in xhci_halt() Mathias Nyman
@ 2022-03-03 10:26 ` Mathias Nyman
  8 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Linyu Yuan, Mathias Nyman

From: Linyu Yuan <quic_linyyuan@quicinc.com>

The ret/retval will be set when it used, no need to init at definition.

[modified subject line -Mathias]
Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1aa10db23fbb..642610c78f58 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -325,7 +325,7 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
  */
 static int xhci_setup_msix(struct xhci_hcd *xhci)
 {
-	int i, ret = 0;
+	int i, ret;
 	struct usb_hcd *hcd = xhci_to_hcd(xhci);
 	struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
 
@@ -579,7 +579,7 @@ static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci)
 static int xhci_init(struct usb_hcd *hcd)
 {
 	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
-	int retval = 0;
+	int retval;
 
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init");
 	spin_lock_init(&xhci->lock);
@@ -3975,7 +3975,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
 	struct xhci_command *command;
 	unsigned long flags;
 	u32 state;
-	int ret = 0;
+	int ret;
 
 	command = xhci_alloc_command(xhci, true, GFP_KERNEL);
 	if (!command)
@@ -4011,7 +4011,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
 
 	xhci_free_command(xhci, command);
 
-	return ret;
+	return 0;
 }
 
 /*
-- 
2.25.1


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

* Re: [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx()
  2022-03-03 10:26 ` [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx() Mathias Nyman
@ 2022-03-03 10:43   ` Anssi Hannula
  2022-03-03 10:59     ` Mathias Nyman
  0 siblings, 1 reply; 12+ messages in thread
From: Anssi Hannula @ 2022-03-03 10:43 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: linux-usb, stable, gregkh

Hi,

On 3.3.2022 12.26, Mathias Nyman wrote:
> From: Anssi Hannula <anssi.hannula@bitwise.fi>
>
> xhci_decode_ctrl_ctx() returns the untouched buffer as-is if both "drop"
> and "add" parameters are zero.
>
> Fix the function to return an empty string in that case.
>
> It was not immediately clear from the possible call chains whether this
> issue is currently actually triggerable or not.
>
> Note that before commit 4843b4b5ec64 ("xhci: fix even more unsafe memory
> Cc: stable@vger.kernel.org
> usage in xhci tracing") the result effect in the failure case was different
> as a static buffer was used here, but the code still worked incorrectly.

You added the Cc-stable line a few lines too early above :)

> Fixes: 90d6d5731da7 ("xhci: Add tracing for input control context")
> Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
>
> commit 4843b4b5ec64 ("xhci: fix even more unsafe memory usage in xhci tracing")
> ---
>  drivers/usb/host/xhci.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> index 1d83ddace482..473a33ce299e 100644
> --- a/drivers/usb/host/xhci.h
> +++ b/drivers/usb/host/xhci.h
> @@ -2468,6 +2468,8 @@ static inline const char *xhci_decode_ctrl_ctx(char *str,
>  	unsigned int	bit;
>  	int		ret = 0;
>  
> +	str[0] = '\0';
> +
>  	if (drop) {
>  		ret = sprintf(str, "Drop:");
>  		for_each_set_bit(bit, &drop, 32)


-- 
Anssi Hannula / Bitwise Oy
+358 503803997


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

* Re: [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx()
  2022-03-03 10:43   ` Anssi Hannula
@ 2022-03-03 10:59     ` Mathias Nyman
  0 siblings, 0 replies; 12+ messages in thread
From: Mathias Nyman @ 2022-03-03 10:59 UTC (permalink / raw)
  To: Anssi Hannula; +Cc: linux-usb, stable, gregkh

On 3.3.2022 12.43, Anssi Hannula wrote:
> Hi,
> 
> On 3.3.2022 12.26, Mathias Nyman wrote:
>> From: Anssi Hannula <anssi.hannula@bitwise.fi>
>>
>> xhci_decode_ctrl_ctx() returns the untouched buffer as-is if both "drop"
>> and "add" parameters are zero.
>>
>> Fix the function to return an empty string in that case.
>>
>> It was not immediately clear from the possible call chains whether this
>> issue is currently actually triggerable or not.
>>
>> Note that before commit 4843b4b5ec64 ("xhci: fix even more unsafe memory
>> Cc: stable@vger.kernel.org
>> usage in xhci tracing") the result effect in the failure case was different
>> as a static buffer was used here, but the code still worked incorrectly.
> 
> You added the Cc-stable line a few lines too early above :)

Oops, copypaste accident. 

I'll resubmit 

Thanks
-Mathias

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

end of thread, other threads:[~2022-03-03 10:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-03 10:26 [PATCH 0/9] xhci cleanups and fixes for usb-next Mathias Nyman
2022-03-03 10:26 ` [PATCH 1/9] xhci: make xhci_handshake timeout for xhci_reset() adjustable Mathias Nyman
2022-03-03 10:26 ` [PATCH 2/9] xhci: fix garbage USBSTS being logged in some cases Mathias Nyman
2022-03-03 10:26 ` [PATCH 3/9] xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx() Mathias Nyman
2022-03-03 10:43   ` Anssi Hannula
2022-03-03 10:59     ` Mathias Nyman
2022-03-03 10:26 ` [PATCH 4/9] xhci: fix runtime PM imbalance in USB2 resume Mathias Nyman
2022-03-03 10:26 ` [PATCH 5/9] usb: host: xhci: use ffs() in xhci_mem_init() Mathias Nyman
2022-03-03 10:26 ` [PATCH 6/9] usb: host: xhci: fix a comment typo " Mathias Nyman
2022-03-03 10:26 ` [PATCH 7/9] usb: host: xhci: update hci_version operation in xhci_gen_setup() Mathias Nyman
2022-03-03 10:26 ` [PATCH 8/9] usb: host: xhci: add blank line in xhci_halt() Mathias Nyman
2022-03-03 10:26 ` [PATCH 9/9] usb: host: xhci: Remove some unnecessary return value initializations Mathias Nyman

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