* [PATCH] xhci: ring: use get_unaligned_le32() for setup packet
@ 2026-09-10 12:36 Adriano Cordova
2026-09-10 14:54 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: Adriano Cordova @ 2026-09-10 12:36 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, Sarah Sharp, Adriano Cordova
The setup packet maps directly onto the two little-endian data words,
so read it with get_unaligned_le32() instead of manipulating
bRequestType/bRequest/wValue/wIndex/wLength by hand. No functional
change.
Signed-off-by: Adriano Cordova <adrianox@gmail.com>
---
drivers/usb/host/xhci-ring.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index ec278a9f9540..e428d3794717 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -58,6 +58,7 @@
#include <linux/string_choices.h>
#include <linux/dma-mapping.h>
#include <linux/bitfield.h>
+#include <linux/unaligned.h>
#include "xhci.h"
#include "xhci-trace.h"
@@ -3837,7 +3838,6 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
start_cycle = ep_ring->cycle_state;
/* Queue setup TRB - see section 6.4.1.2.1 */
- /* FIXME better way to translate setup_packet into two u32 fields? */
setup = (struct usb_ctrlrequest *) urb->setup_packet;
field = 0;
field |= TRB_IDT | TRB_TYPE(TRB_SETUP);
@@ -3855,8 +3855,8 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
}
queue_trb(xhci, ep_ring, true,
- setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16,
- le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16,
+ get_unaligned_le32(setup),
+ get_unaligned_le32((u8 *)setup + sizeof(u32)),
TRB_LEN(8) | TRB_INTR_TARGET(0),
/* Immediate data in pointer */
field);
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] xhci: ring: use get_unaligned_le32() for setup packet
2026-09-10 12:36 [PATCH] xhci: ring: use get_unaligned_le32() for setup packet Adriano Cordova
@ 2026-09-10 14:54 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2026-09-10 14:54 UTC (permalink / raw)
To: Adriano Cordova
Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-kernel, Sarah Sharp
On Thu, Sep 10, 2026 at 09:36:29AM -0300, Adriano Cordova wrote:
> The setup packet maps directly onto the two little-endian data words,
> so read it with get_unaligned_le32() instead of manipulating
> bRequestType/bRequest/wValue/wIndex/wLength by hand. No functional
> change.
>
> Signed-off-by: Adriano Cordova <adrianox@gmail.com>
> ---
Nobody asked my opinion, but I'll give it anyway.
The original code was fine as it was, regardless of the FIXME comment.
Using get_unaligned_32() relies on details of the layout of the setup
packet and is harder for a reader to follow. I would not do it unless
it provided a measurable improvement in speed -- which it doesn't.
Alan Stern
> drivers/usb/host/xhci-ring.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index ec278a9f9540..e428d3794717 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -58,6 +58,7 @@
> #include <linux/string_choices.h>
> #include <linux/dma-mapping.h>
> #include <linux/bitfield.h>
> +#include <linux/unaligned.h>
>
> #include "xhci.h"
> #include "xhci-trace.h"
> @@ -3837,7 +3838,6 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
> start_cycle = ep_ring->cycle_state;
>
> /* Queue setup TRB - see section 6.4.1.2.1 */
> - /* FIXME better way to translate setup_packet into two u32 fields? */
> setup = (struct usb_ctrlrequest *) urb->setup_packet;
> field = 0;
> field |= TRB_IDT | TRB_TYPE(TRB_SETUP);
> @@ -3855,8 +3855,8 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
> }
>
> queue_trb(xhci, ep_ring, true,
> - setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16,
> - le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16,
> + get_unaligned_le32(setup),
> + get_unaligned_le32((u8 *)setup + sizeof(u32)),
> TRB_LEN(8) | TRB_INTR_TARGET(0),
> /* Immediate data in pointer */
> field);
> --
> 2.51.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-10 14:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 12:36 [PATCH] xhci: ring: use get_unaligned_le32() for setup packet Adriano Cordova
2026-09-10 14:54 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®