public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Petr Tesarik <ptesarik@suse.com>
Subject: [PATCH v2] usb: core: warn if a GFP zone flag is passed to hcd_buffer_alloc()
Date: Tue, 25 Mar 2025 14:40:00 +0100	[thread overview]
Message-ID: <20250325134000.575794-1-ptesarik@suse.com> (raw)
In-Reply-To: <20250320154733.392410-1-ptesarik@suse.com>

Remove a misleading comment and issue a warning if a zone modifier is
specified when allocating a hcd buffer.

There is no valid use case for a GFP zone modifier in hcd_buffer_alloc():
- PIO mode can use any kernel-addressable memory
- dma_alloc_coherent() ignores memory zone bits

This function is called by usb_alloc_coherent() and indirectly by
usb_submit_urb(). Despite the comment, no in-tree users currently pass
GFP_DMA.

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

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 87230869e1fa..10844cd42e66 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,12 @@ void *hcd_buffer_alloc(
 	if (hcd->localmem_pool)
 		return gen_pool_dma_alloc(hcd->localmem_pool, size, dma);
 
+	/*
+	 * Zone modifiers are ignored by DMA API, and PIO should always use
+	 * GFP_KERNEL.
+	 */
+	WARN_ON_ONCE(mem_flags & GFP_ZONEMASK);
+
 	/* some USB hosts just use PIO */
 	if (!hcd_uses_dma(hcd)) {
 		*dma = ~(dma_addr_t) 0;
-- 
2.48.1


  reply	other threads:[~2025-03-25 13:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 15:47 [PATCH] usb: core: do not allocate buffers from a DMA zone unnecessarily Petr Tesarik
2025-03-25 13:40 ` Petr Tesarik [this message]
2025-03-25 13:54   ` [PATCH v2] usb: core: warn if a GFP zone flag is passed to hcd_buffer_alloc() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250325134000.575794-1-ptesarik@suse.com \
    --to=ptesarik@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox