All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/7] xhci: mem: Short cleanup series
@ 2023-02-06 16:10 Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations Andy Shevchenko
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

Clean up xhci-mem.c a bit using latest and greatest Linux kernel
features.

Andy Shevchenko (7):
  xhci: mem: Carefully calculate size for memory allocations
  xhci: mem: Use __GFP_ZERO instead of explicit memset() call
  xhci: mem: Get rid of redundant 'else'
  xhci: mem: Drop useless return:s
  xhci: mem: Use while (i--) pattern to clean up
  xhci: mem: Replace explicit castings with appropriate specifiers
  xhci: mem: Join string literals back

 drivers/usb/host/xhci-mem.c | 85 +++++++++++++++----------------------
 1 file changed, 35 insertions(+), 50 deletions(-)

-- 
2.39.1


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

* [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call Andy Shevchenko
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

Carefully calculate size for memory allocations, i.e. with help
of size_mul() macro from overflow.h.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d0a9467aa5fc..c385513ad00b 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/usb.h>
+#include <linux/overflow.h>
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/dmapool.h>
@@ -568,7 +569,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 		gfp_t mem_flags)
 {
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
-	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
+	size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
 		return dma_alloc_coherent(dev, size,
@@ -1660,7 +1661,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 		goto fail_sp;
 
 	xhci->scratchpad->sp_array = dma_alloc_coherent(dev,
-				     num_sp * sizeof(u64),
+				     size_mul(sizeof(u64), num_sp),
 				     &xhci->scratchpad->sp_dma, flags);
 	if (!xhci->scratchpad->sp_array)
 		goto fail_sp2;
@@ -1799,7 +1800,7 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
 	struct xhci_segment *seg;
 	struct xhci_erst_entry *entry;
 
-	size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs;
+	size = size_mul(sizeof(struct xhci_erst_entry), evt_ring->num_segs);
 	erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
 					   size, &erst->erst_dma_addr, flags);
 	if (!erst->entries)
@@ -1830,7 +1831,7 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
 	if (!ir)
 		return;
 
-	erst_size = sizeof(struct xhci_erst_entry) * (ir->erst.num_entries);
+	erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries;
 	if (ir->erst.entries)
 		dma_free_coherent(dev, erst_size,
 				  ir->erst.entries,
-- 
2.39.1


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

* [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-07 15:11   ` Mathias Nyman
  2023-02-06 16:10 ` [PATCH v1 3/7] xhci: mem: Get rid of redundant 'else' Andy Shevchenko
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

Use __GFP_ZERO instead of explicit memset() call in
xhci_alloc_stream_ctx().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index c385513ad00b..768adcb544a7 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -571,6 +571,8 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
 
+	mem_flags |= __GFP_ZERO;
+
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
 		return dma_alloc_coherent(dev, size,
 				dma, mem_flags);
@@ -643,8 +645,6 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
 			mem_flags);
 	if (!stream_info->stream_ctx_array)
 		goto cleanup_ring_array;
-	memset(stream_info->stream_ctx_array, 0,
-			sizeof(struct xhci_stream_ctx)*num_stream_ctxs);
 
 	/* Allocate everything needed to free the stream rings later */
 	stream_info->free_streams_command =
-- 
2.39.1


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

* [PATCH v1 3/7] xhci: mem: Get rid of redundant 'else'
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 4/7] xhci: mem: Drop useless return:s Andy Shevchenko
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

In the snippets like the following

	if (...)
		return / goto / break / continue ...;
	else
		...

the 'else' is redundant. Get rid of it.

While at it, make if chain sorted from testing bigger values to smaller.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 768adcb544a7..34f5ba19471e 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -574,14 +574,11 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 	mem_flags |= __GFP_ZERO;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
-		return dma_alloc_coherent(dev, size,
-				dma, mem_flags);
-	else if (size <= SMALL_STREAM_ARRAY_SIZE)
-		return dma_pool_alloc(xhci->small_streams_pool,
-				mem_flags, dma);
+		return dma_alloc_coherent(dev, size, dma, mem_flags);
+	if (size > SMALL_STREAM_ARRAY_SIZE)
+		return dma_pool_alloc(xhci->medium_streams_pool, mem_flags, dma);
 	else
-		return dma_pool_alloc(xhci->medium_streams_pool,
-				mem_flags, dma);
+		return dma_pool_alloc(xhci->small_streams_pool, mem_flags, dma);
 }
 
 struct xhci_ring *xhci_dma_to_transfer_ring(
@@ -1401,8 +1398,9 @@ static u32 xhci_get_max_esit_payload(struct usb_device *udev,
 	if ((udev->speed >= USB_SPEED_SUPER_PLUS) &&
 	    USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes))
 		return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval);
+
 	/* SuperSpeed or SuperSpeedPlus Isoc ep with less than 48k per esit */
-	else if (udev->speed >= USB_SPEED_SUPER)
+	if (udev->speed >= USB_SPEED_SUPER)
 		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
 
 	max_packet = usb_endpoint_maxp(&ep->desc);
-- 
2.39.1


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

* [PATCH v1 4/7] xhci: mem: Drop useless return:s
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-02-06 16:10 ` [PATCH v1 3/7] xhci: mem: Get rid of redundant 'else' Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 5/7] xhci: mem: Use while (i--) pattern to clean up Andy Shevchenko
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

When function returns void and we have if-else-if chain, there is
no need to explicitly call return. Drop them and indent lines better.

While at it, make if chain sorted from testing bigger values to smaller.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 34f5ba19471e..5c873e62c4d3 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -544,14 +544,11 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
 	size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
-		dma_free_coherent(dev, size,
-				stream_ctx, dma);
-	else if (size <= SMALL_STREAM_ARRAY_SIZE)
-		return dma_pool_free(xhci->small_streams_pool,
-				stream_ctx, dma);
+		dma_free_coherent(dev, size, stream_ctx, dma);
+	else if (size > SMALL_STREAM_ARRAY_SIZE)
+		dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma);
 	else
-		return dma_pool_free(xhci->medium_streams_pool,
-				stream_ctx, dma);
+		dma_pool_free(xhci->small_streams_pool, stream_ctx, dma);
 }
 
 /*
-- 
2.39.1


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

* [PATCH v1 5/7] xhci: mem: Use while (i--) pattern to clean up
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
                   ` (3 preceding siblings ...)
  2023-02-06 16:10 ` [PATCH v1 4/7] xhci: mem: Drop useless return:s Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 6/7] xhci: mem: Replace explicit castings with appropriate specifiers Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 7/7] xhci: mem: Join string literals back Andy Shevchenko
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

Use more natural while (i--) patter to clean up allocated resources.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 5c873e62c4d3..a3351b11efa5 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1681,11 +1681,10 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 	return 0;
 
  fail_sp4:
-	for (i = i - 1; i >= 0; i--) {
+	while (i--)
 		dma_free_coherent(dev, xhci->page_size,
 				    xhci->scratchpad->sp_buffers[i],
 				    xhci->scratchpad->sp_array[i]);
-	}
 
 	kfree(xhci->scratchpad->sp_buffers);
 
-- 
2.39.1


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

* [PATCH v1 6/7] xhci: mem: Replace explicit castings with appropriate specifiers
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
                   ` (4 preceding siblings ...)
  2023-02-06 16:10 ` [PATCH v1 5/7] xhci: mem: Use while (i--) pattern to clean up Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  2023-02-06 16:10 ` [PATCH v1 7/7] xhci: mem: Join string literals back Andy Shevchenko
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

There is no need to have explicit castings when we have specific pointer extensions
Replace the explicit castings with appropriate specifiers.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index a3351b11efa5..fef74e7c20fc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -668,8 +668,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
 			cur_ring->cycle_state;
 		stream_info->stream_ctx_array[cur_stream].stream_ring =
 			cpu_to_le64(addr);
-		xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
-				cur_stream, (unsigned long long) addr);
+		xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr);
 
 		ret = xhci_update_stream_mapping(cur_ring, mem_flags);
 		if (ret) {
@@ -979,16 +978,14 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
 	if (!dev->out_ctx)
 		goto fail;
 
-	xhci_dbg(xhci, "Slot %d output ctx = 0x%llx (dma)\n", slot_id,
-			(unsigned long long)dev->out_ctx->dma);
+	xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma);
 
 	/* Allocate the (input) device context for address device command */
 	dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags);
 	if (!dev->in_ctx)
 		goto fail;
 
-	xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id,
-			(unsigned long long)dev->in_ctx->dma);
+	xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma);
 
 	/* Initialize the cancellation and bandwidth list for each ep */
 	for (i = 0; i < 31; i++) {
@@ -2353,8 +2350,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 		goto fail;
 	xhci->dcbaa->dma = dma;
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
-			"// Device context base array address = 0x%llx (DMA), %p (virt)",
-			(unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
+			"// Device context base array address = 0x%pad (DMA), %p (virt)",
+			&xhci->dcbaa->dma, xhci->dcbaa);
 	xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
 
 	/*
@@ -2395,8 +2392,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 		goto fail;
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Allocated command ring at %p", xhci->cmd_ring);
-	xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%llx",
-			(unsigned long long)xhci->cmd_ring->first_seg->dma);
+	xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad",
+			&xhci->cmd_ring->first_seg->dma);
 
 	/* Set the address in the Command Ring Control register */
 	val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
-- 
2.39.1


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

* [PATCH v1 7/7] xhci: mem: Join string literals back
  2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
                   ` (5 preceding siblings ...)
  2023-02-06 16:10 ` [PATCH v1 6/7] xhci: mem: Replace explicit castings with appropriate specifiers Andy Shevchenko
@ 2023-02-06 16:10 ` Andy Shevchenko
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-06 16:10 UTC (permalink / raw)
  To: Mathias Nyman, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman, Andy Shevchenko

For easy grepping on debug purposes join string literals back in
the messages.

No functional change.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index fef74e7c20fc..9bdf2ed85772 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -609,8 +609,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
 	int ret;
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 
-	xhci_dbg(xhci, "Allocating %u streams and %u "
-			"stream context array entries.\n",
+	xhci_dbg(xhci, "Allocating %u streams and %u stream context array entries.\n",
 			num_streams, num_stream_ctxs);
 	if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) {
 		xhci_dbg(xhci, "Command ring has no reserved TRBs available\n");
@@ -1952,8 +1951,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter
 	deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg,
 			ir->event_ring->dequeue);
 	if (!deq)
-		xhci_warn(xhci, "WARN something wrong with SW event ring "
-				"dequeue ptr.\n");
+		xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n");
 	/* Update HC event ring dequeue pointer */
 	temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
 	temp &= ERST_PTR_MASK;
@@ -1962,8 +1960,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter
 	 */
 	temp &= ~ERST_EHB;
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
-			"// Write event ring dequeue pointer, "
-			"preserving EHB bit");
+		       "// Write event ring dequeue pointer, preserving EHB bit");
 	xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
 			&ir->ir_set->erst_dequeue);
 }
@@ -1996,8 +1993,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 	} else if (major_revision <= 0x02) {
 		rhub = &xhci->usb2_rhub;
 	} else {
-		xhci_warn(xhci, "Ignoring unknown port speed, "
-				"Ext Cap %p, revision = 0x%x\n",
+		xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n",
 				addr, major_revision);
 		/* Ignoring port protocol we can't understand. FIXME */
 		return;
@@ -2012,9 +2008,8 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 	port_offset = XHCI_EXT_PORT_OFF(temp);
 	port_count = XHCI_EXT_PORT_COUNT(temp);
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
-			"Ext Cap %p, port offset = %u, "
-			"count = %u, revision = 0x%x",
-			addr, port_offset, port_count, major_revision);
+		       "Ext Cap %p, port offset = %u, count = %u, revision = 0x%x",
+		       addr, port_offset, port_count, major_revision);
 	/* Port count includes the current port offset */
 	if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
 		/* WTF? "Valid values are ‘1’ to MaxPorts" */
@@ -2071,10 +2066,8 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 		struct xhci_port *hw_port = &xhci->hw_ports[i];
 		/* Duplicate entry.  Ignore the port if the revisions differ. */
 		if (hw_port->rhub) {
-			xhci_warn(xhci, "Duplicate port entry, Ext Cap %p,"
-					" port %u\n", addr, i);
-			xhci_warn(xhci, "Port was marked as USB %u, "
-					"duplicated as USB %u\n",
+			xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i);
+			xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n",
 					hw_port->rhub->maj_rev, major_revision);
 			/* Only adjust the roothub port counts if we haven't
 			 * found a similar duplicate.
@@ -2413,8 +2406,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	val = readl(&xhci->cap_regs->db_off);
 	val &= DBOFF_MASK;
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
-			"// Doorbell array is located at offset 0x%x"
-			" from cap regs base addr", val);
+		       "// Doorbell array is located at offset 0x%x from cap regs base addr",
+		       val);
 	xhci->dba = (void __iomem *) xhci->cap_regs + val;
 	/* Set ir_set to interrupt register set 0 */
 
-- 
2.39.1


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

* Re: [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call
  2023-02-06 16:10 ` [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call Andy Shevchenko
@ 2023-02-07 15:11   ` Mathias Nyman
  2023-02-07 22:49     ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Mathias Nyman @ 2023-02-07 15:11 UTC (permalink / raw)
  To: Andy Shevchenko, linux-usb, linux-kernel
  Cc: Mathias Nyman, Greg Kroah-Hartman

On 6.2.2023 18.10, Andy Shevchenko wrote:
> Use __GFP_ZERO instead of explicit memset() call in
> xhci_alloc_stream_ctx().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/usb/host/xhci-mem.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index c385513ad00b..768adcb544a7 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -571,6 +571,8 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
>   	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
>   	size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
>   
> +	mem_flags |= __GFP_ZERO;
> +

How about calling dma_pool_zalloc() instead of setting __GFP_ZERO flag?
Memory returned by dma_alloc_coherent() should already be zeroed if I remember correctly

-Mathias



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

* Re: [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call
  2023-02-07 15:11   ` Mathias Nyman
@ 2023-02-07 22:49     ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-02-07 22:49 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: linux-usb, linux-kernel, Mathias Nyman, Greg Kroah-Hartman

On Tue, Feb 07, 2023 at 05:11:23PM +0200, Mathias Nyman wrote:
> On 6.2.2023 18.10, Andy Shevchenko wrote:
> > Use __GFP_ZERO instead of explicit memset() call in
> > xhci_alloc_stream_ctx().

...

> > +	mem_flags |= __GFP_ZERO;
> 
> How about calling dma_pool_zalloc() instead of setting __GFP_ZERO flag?
> Memory returned by dma_alloc_coherent() should already be zeroed if I remember correctly

That will work too.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-02-07 22:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-06 16:10 [PATCH v1 0/7] xhci: mem: Short cleanup series Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call Andy Shevchenko
2023-02-07 15:11   ` Mathias Nyman
2023-02-07 22:49     ` Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 3/7] xhci: mem: Get rid of redundant 'else' Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 4/7] xhci: mem: Drop useless return:s Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 5/7] xhci: mem: Use while (i--) pattern to clean up Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 6/7] xhci: mem: Replace explicit castings with appropriate specifiers Andy Shevchenko
2023-02-06 16:10 ` [PATCH v1 7/7] xhci: mem: Join string literals back Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.