2021-08-25 10:53:34

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: [PATCH 1/3] usb: core: hcd: Modularize HCD stop configuration in usb_stop_hcd()

No functional change. Since configuration to stop HCD is invoked from
multiple places, group all of them in usb_stop_hcd().

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
---
drivers/usb/core/hcd.c | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0f8b7c93310e..775f0456f0ad 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2760,6 +2760,26 @@ static void usb_put_invalidate_rhdev(struct usb_hcd *hcd)
usb_put_dev(rhdev);
}

+/**
+ * usb_stop_hcd - Halt the HCD
+ * @hcd: the usb_hcd that has to be halted
+ *
+ * Stop the timer and invoke ->stop() callback on the HCD
+ */
+static void usb_stop_hcd(struct usb_hcd *hcd)
+{
+ hcd->rh_pollable = 0;
+ clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+ del_timer_sync(&hcd->rh_timer);
+
+ hcd->driver->stop(hcd);
+ hcd->state = HC_STATE_HALT;
+
+ /* In case the HCD restarted the timer, stop it again. */
+ clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+ del_timer_sync(&hcd->rh_timer);
+}
+
/**
* usb_add_hcd - finish generic HCD structure initialization and register
* @hcd: the usb_hcd structure to initialize
@@ -2946,13 +2966,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
return retval;

err_register_root_hub:
- hcd->rh_pollable = 0;
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
- hcd->driver->stop(hcd);
- hcd->state = HC_STATE_HALT;
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
+ usb_stop_hcd(hcd);
err_hcd_driver_start:
if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
free_irq(irqnum, hcd);
@@ -3022,16 +3036,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
* interrupt occurs), but usb_hcd_poll_rh_status() won't invoke
* the hub_status_data() callback.
*/
- hcd->rh_pollable = 0;
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
-
- hcd->driver->stop(hcd);
- hcd->state = HC_STATE_HALT;
-
- /* In case the HCD restarted the timer, stop it again. */
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
+ usb_stop_hcd(hcd);

if (usb_hcd_is_primary_hcd(hcd)) {
if (hcd->irq > 0)
--
2.17.1


2021-08-25 15:33:42

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 1/3] usb: core: hcd: Modularize HCD stop configuration in usb_stop_hcd()

On Wed, Aug 25, 2021 at 04:21:30PM +0530, Kishon Vijay Abraham I wrote:
> No functional change. Since configuration to stop HCD is invoked from
> multiple places, group all of them in usb_stop_hcd().
>
> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
> ---
> drivers/usb/core/hcd.c | 39 ++++++++++++++++++++++-----------------
> 1 file changed, 22 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 0f8b7c93310e..775f0456f0ad 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2760,6 +2760,26 @@ static void usb_put_invalidate_rhdev(struct usb_hcd *hcd)
> usb_put_dev(rhdev);
> }
>
> +/**
> + * usb_stop_hcd - Halt the HCD
> + * @hcd: the usb_hcd that has to be halted
> + *
> + * Stop the timer and invoke ->stop() callback on the HCD

This comment is now somewhat out of context. It should be rephrased
to say "Stop the root-hub polling timer and invoke the HCD's ->stop
callback."

Apart from that,

Acked-by: Alan Stern <[email protected]>

Alan Stern

> + */
> +static void usb_stop_hcd(struct usb_hcd *hcd)
> +{
> + hcd->rh_pollable = 0;
> + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> + del_timer_sync(&hcd->rh_timer);
> +
> + hcd->driver->stop(hcd);
> + hcd->state = HC_STATE_HALT;
> +
> + /* In case the HCD restarted the timer, stop it again. */
> + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> + del_timer_sync(&hcd->rh_timer);
> +}
> +
> /**
> * usb_add_hcd - finish generic HCD structure initialization and register
> * @hcd: the usb_hcd structure to initialize
> @@ -2946,13 +2966,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
> return retval;
>
> err_register_root_hub:
> - hcd->rh_pollable = 0;
> - clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> - del_timer_sync(&hcd->rh_timer);
> - hcd->driver->stop(hcd);
> - hcd->state = HC_STATE_HALT;
> - clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> - del_timer_sync(&hcd->rh_timer);
> + usb_stop_hcd(hcd);
> err_hcd_driver_start:
> if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
> free_irq(irqnum, hcd);
> @@ -3022,16 +3036,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
> * interrupt occurs), but usb_hcd_poll_rh_status() won't invoke
> * the hub_status_data() callback.
> */
> - hcd->rh_pollable = 0;
> - clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> - del_timer_sync(&hcd->rh_timer);
> -
> - hcd->driver->stop(hcd);
> - hcd->state = HC_STATE_HALT;
> -
> - /* In case the HCD restarted the timer, stop it again. */
> - clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
> - del_timer_sync(&hcd->rh_timer);
> + usb_stop_hcd(hcd);
>
> if (usb_hcd_is_primary_hcd(hcd)) {
> if (hcd->irq > 0)
> --
> 2.17.1
>