public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: core: do not allocate buffers from a DMA zone unnecessarily
@ 2025-03-20 15:47 Petr Tesarik
  2025-03-25 13:40 ` [PATCH v2] usb: core: warn if a GFP zone flag is passed to hcd_buffer_alloc() Petr Tesarik
  0 siblings, 1 reply; 14+ messages in thread
From: Petr Tesarik @ 2025-03-20 15:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Petr Tesarik

There is no reason to keep GFP zone modifiers in hcd_buffer_alloc():
- PIO mode can use any kernel-addressable memory
- dma_alloc_coherent() ignores memory zone bits

The only place where GFP zone bits are used is when dma_pool_alloc() needs
to allocate a new struct dma_page, but that is an omission rather than
intention.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 drivers/usb/core/buffer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 87230869e1fa..2be4c2a5b214 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -108,10 +108,6 @@ void hcd_buffer_destroy(struct usb_hcd *hcd)
 }
 
 
-/* sometimes alloc/free could use kmalloc with GFP_DMA, for
- * better sharing and to leverage mm/slab.c intelligence.
- */
-
 void *hcd_buffer_alloc(
 	struct usb_bus		*bus,
 	size_t			size,
@@ -128,6 +124,9 @@ void *hcd_buffer_alloc(
 	if (hcd->localmem_pool)
 		return gen_pool_dma_alloc(hcd->localmem_pool, size, dma);
 
+	/* DMA API ignores zone modifiers, and PIO should go with default */
+	mem_flags &= ~GFP_ZONEMASK;
+
 	/* some USB hosts just use PIO */
 	if (!hcd_uses_dma(hcd)) {
 		*dma = ~(dma_addr_t) 0;
-- 
2.48.1


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

end of thread, other threads:[~2025-04-16 13:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 15:47 [PATCH] usb: core: do not allocate buffers from a DMA zone unnecessarily Petr Tesarik
2025-03-25 13:40 ` [PATCH v2] usb: core: warn if a GFP zone flag is passed to hcd_buffer_alloc() Petr Tesarik
2025-03-25 13:54   ` Petr Tesarik
2025-04-09 15:40   ` Petr Tesařík
2025-04-10  6:10     ` Greg Kroah-Hartman
2025-04-11 13:57   ` Greg Kroah-Hartman
2025-04-14  7:02     ` Petr Tesarik
2025-04-14  7:12       ` Greg Kroah-Hartman
2025-04-14  7:57         ` Petr Tesarik
2025-04-15  7:53       ` Oliver Neukum
2025-04-16  7:48         ` Petr Tesarik
2025-04-16  8:45           ` Oliver Neukum
2025-04-16 10:47             ` Petr Tesarik
2025-04-16 13:08               ` Oliver Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox