* [PATCH v1] usb: core: replace usb_sndaddr0pipe macro with usb_sndctrlpipe
@ 2025-02-19 8:36 Stefan Eichenberger
2025-02-19 15:17 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Eichenberger @ 2025-02-19 8:36 UTC (permalink / raw)
To: gregkh, stern; +Cc: linux-usb, linux-kernel, Stefan Eichenberger
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
The usb_sndaddr0pipe macro is only used in the hub_set_address function.
Replace it with usb_sndctrlpipe which provides the same functionality
but would also consider the endpoint device number.
If the device has not been initialised, it is safe to use
usb_sndctrlpipe in this context because udev->devnum is set to 0.
Therefore, this change does not affect behaviour, but reduces code
complexity by reusing the existing macro.
Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
---
Even though this patch does not fix a bug it is related to the following
discussion and addresses the change proposed by Alan:
https://lore.kernel.org/all/aa0c06f6-f997-4bcf-a5a3-6b17f6355fca@rowland.harvard.edu/
---
drivers/usb/core/hub.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 59e38780f76d0..66dfdf0bab90b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4697,8 +4697,6 @@ void usb_ep0_reinit(struct usb_device *udev)
}
EXPORT_SYMBOL_GPL(usb_ep0_reinit);
-#define usb_sndaddr0pipe() (PIPE_CONTROL << 30)
-
static int hub_set_address(struct usb_device *udev, int devnum)
{
int retval;
@@ -4722,7 +4720,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
if (hcd->driver->address_device)
retval = hcd->driver->address_device(hcd, udev, timeout_ms);
else
- retval = usb_control_msg(udev, usb_sndaddr0pipe(),
+ retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
USB_REQ_SET_ADDRESS, 0, devnum, 0,
NULL, 0, timeout_ms);
if (retval == 0) {
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] usb: core: replace usb_sndaddr0pipe macro with usb_sndctrlpipe
2025-02-19 8:36 [PATCH v1] usb: core: replace usb_sndaddr0pipe macro with usb_sndctrlpipe Stefan Eichenberger
@ 2025-02-19 15:17 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2025-02-19 15:17 UTC (permalink / raw)
To: Stefan Eichenberger; +Cc: gregkh, linux-usb, linux-kernel, Stefan Eichenberger
On Wed, Feb 19, 2025 at 09:36:44AM +0100, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
>
> The usb_sndaddr0pipe macro is only used in the hub_set_address function.
> Replace it with usb_sndctrlpipe which provides the same functionality
> but would also consider the endpoint device number.
>
> If the device has not been initialised, it is safe to use
> usb_sndctrlpipe in this context because udev->devnum is set to 0.
> Therefore, this change does not affect behaviour, but reduces code
> complexity by reusing the existing macro.
>
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> ---
> Even though this patch does not fix a bug it is related to the following
> discussion and addresses the change proposed by Alan:
> https://lore.kernel.org/all/aa0c06f6-f997-4bcf-a5a3-6b17f6355fca@rowland.harvard.edu/
> ---
Acked-by: Alan Stern <stern@rowland.harvard.edu>
> drivers/usb/core/hub.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 59e38780f76d0..66dfdf0bab90b 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -4697,8 +4697,6 @@ void usb_ep0_reinit(struct usb_device *udev)
> }
> EXPORT_SYMBOL_GPL(usb_ep0_reinit);
>
> -#define usb_sndaddr0pipe() (PIPE_CONTROL << 30)
> -
> static int hub_set_address(struct usb_device *udev, int devnum)
> {
> int retval;
> @@ -4722,7 +4720,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
> if (hcd->driver->address_device)
> retval = hcd->driver->address_device(hcd, udev, timeout_ms);
> else
> - retval = usb_control_msg(udev, usb_sndaddr0pipe(),
> + retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
> USB_REQ_SET_ADDRESS, 0, devnum, 0,
> NULL, 0, timeout_ms);
> if (retval == 0) {
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-19 15:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-19 8:36 [PATCH v1] usb: core: replace usb_sndaddr0pipe macro with usb_sndctrlpipe Stefan Eichenberger
2025-02-19 15:17 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox