Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails
@ 2020-07-03 22:50 Martin Blumenstingl
  2020-07-04  5:58 ` Minas Harutyunyan
  2020-07-26 10:04 ` Minas Harutyunyan
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Blumenstingl @ 2020-07-03 22:50 UTC (permalink / raw)
  To: hminas, gregkh, linux-usb
  Cc: linux-kernel, marex, stable, Martin Blumenstingl

Call dwc2_debugfs_exit() and dwc2_hcd_remove() (if the HCD was enabled
earlier) when usb_add_gadget_udc() has failed. This ensures that the
debugfs entries created by dwc2_debugfs_init() as well as the HCD are
cleaned up in the error path.

Fixes: 207324a321a866 ("usb: dwc2: Postponed gadget registration to the udc class driver")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
Changes since v1 at [0]
- also cleanup the HCD as suggested by Minas (thank you!)
- updated the subject accordingly


[0] https://patchwork.kernel.org/patch/11631381/


 drivers/usb/dwc2/platform.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index c347d93eae64..9febae441069 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -582,12 +582,16 @@ static int dwc2_driver_probe(struct platform_device *dev)
 		retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
 		if (retval) {
 			dwc2_hsotg_remove(hsotg);
-			goto error_init;
+			goto error_debugfs;
 		}
 	}
 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
 	return 0;
 
+error_debugfs:
+	dwc2_debugfs_exit(hsotg);
+	if (hsotg->hcd_enabled)
+		dwc2_hcd_remove(hsotg);
 error_init:
 	if (hsotg->params.activate_stm_id_vb_detection)
 		regulator_disable(hsotg->usb33d);
-- 
2.27.0


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

* Re: [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails
  2020-07-03 22:50 [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails Martin Blumenstingl
@ 2020-07-04  5:58 ` Minas Harutyunyan
  2020-07-26 10:04 ` Minas Harutyunyan
  1 sibling, 0 replies; 4+ messages in thread
From: Minas Harutyunyan @ 2020-07-04  5:58 UTC (permalink / raw)
  To: Martin Blumenstingl, gregkh, linux-usb; +Cc: linux-kernel, marex, stable



On 7/4/2020 2:50 AM, Martin Blumenstingl wrote:
> Call dwc2_debugfs_exit() and dwc2_hcd_remove() (if the HCD was enabled
> earlier) when usb_add_gadget_udc() has failed. This ensures that the
> debugfs entries created by dwc2_debugfs_init() as well as the HCD are
> cleaned up in the error path.
> 
> Fixes: 207324a321a866 ("usb: dwc2: Postponed gadget registration to the udc class driver")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Acked-by: Minas Harutyunyan <hminas@synopsys.com>

> ---
> Changes since v1 at [0]
> - also cleanup the HCD as suggested by Minas (thank you!)
> - updated the subject accordingly
> 
> 
> [0] https://urldefense.com/v3/__https://patchwork.kernel.org/patch/11631381/__;!!A4F2R9G_pg!K0ZJIzYVYtrwy2VgxTI28Z_qA995uqmg1dFrMNx3XMQ653ROMKPkt_zQdJe1OOk$
> 
> 
>   drivers/usb/dwc2/platform.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index c347d93eae64..9febae441069 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -582,12 +582,16 @@ static int dwc2_driver_probe(struct platform_device *dev)
>   		retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
>   		if (retval) {
>   			dwc2_hsotg_remove(hsotg);
> -			goto error_init;
> +			goto error_debugfs;
>   		}
>   	}
>   #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
>   	return 0;
>   
> +error_debugfs:
> +	dwc2_debugfs_exit(hsotg);
> +	if (hsotg->hcd_enabled)
> +		dwc2_hcd_remove(hsotg);
>   error_init:
>   	if (hsotg->params.activate_stm_id_vb_detection)
>   		regulator_disable(hsotg->usb33d);
> 

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

* Re: [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails
  2020-07-03 22:50 [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails Martin Blumenstingl
  2020-07-04  5:58 ` Minas Harutyunyan
@ 2020-07-26 10:04 ` Minas Harutyunyan
  2020-07-27 17:35   ` Martin Blumenstingl
  1 sibling, 1 reply; 4+ messages in thread
From: Minas Harutyunyan @ 2020-07-26 10:04 UTC (permalink / raw)
  To: Martin Blumenstingl, gregkh, linux-usb; +Cc: linux-kernel, marex, stable

Hi Martin,

On 7/4/2020 2:50 AM, Martin Blumenstingl wrote:
> Call dwc2_debugfs_exit() and dwc2_hcd_remove() (if the HCD was enabled
> earlier) when usb_add_gadget_udc() has failed. This ensures that the
> debugfs entries created by dwc2_debugfs_init() as well as the HCD are
> cleaned up in the error path.
> 
> Fixes: 207324a321a866 ("usb: dwc2: Postponed gadget registration to the udc class driver")
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
> Changes since v1 at [0]
> - also cleanup the HCD as suggested by Minas (thank you!)
> - updated the subject accordingly
> 
> 
> [0] https://urldefense.com/v3/__https://patchwork.kernel.org/patch/11631381/__;!!A4F2R9G_pg!K0ZJIzYVYtrwy2VgxTI28Z_qA995uqmg1dFrMNx3XMQ653ROMKPkt_zQdJe1OOk$
> 
> 
>   drivers/usb/dwc2/platform.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index c347d93eae64..9febae441069 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -582,12 +582,16 @@ static int dwc2_driver_probe(struct platform_device *dev)
>   		retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
>   		if (retval) {
>   			dwc2_hsotg_remove(hsotg);
> -			goto error_init;
> +			goto error_debugfs;
>   		}
>   	}
>   #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
>   	return 0;
>  

Kernel test robot found issue:
 >> warning: unused label 'error_debugfs' [-Wunused-label]
    error_debugfs:
    ^~~~~~~~~~~~~~
    1 warning generated.

So, 'error_debugfs:' label should be under #if/#endif:

#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
         IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
error_debugfs:
#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */

Or you have other suggestion?

Could you please fix this issue and submit new version of patch.

Thanks,
Minas


> +error_debugfs:
> +	dwc2_debugfs_exit(hsotg);
> +	if (hsotg->hcd_enabled)
> +		dwc2_hcd_remove(hsotg);
>   error_init:
>   	if (hsotg->params.activate_stm_id_vb_detection)
>   		regulator_disable(hsotg->usb33d);
> 

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

* Re: [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails
  2020-07-26 10:04 ` Minas Harutyunyan
@ 2020-07-27 17:35   ` Martin Blumenstingl
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Blumenstingl @ 2020-07-27 17:35 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: gregkh, linux-usb, linux-kernel, marex, stable

Hello Minas,

On Sun, Jul 26, 2020 at 12:04 PM Minas Harutyunyan
<Minas.Harutyunyan@synopsys.com> wrote:
[...]
> Kernel test robot found issue:
>  >> warning: unused label 'error_debugfs' [-Wunused-label]
>     error_debugfs:
>     ^~~~~~~~~~~~~~
>     1 warning generated.
>
> So, 'error_debugfs:' label should be under #if/#endif:
>
> #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
>          IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
> error_debugfs:
> #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
>
> Or you have other suggestion?
unfortunately I have no better idea

> Could you please fix this issue and submit new version of patch.
I'm going to cover everything I add inside the same #if (not just the
error label).
if any additional label is added (above) in the future then the code
that I'm adding must not be executed when that #if evaluates to false

v3 is coming in the next few minutes.


Best regards,
Martin

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 22:50 [PATCH for-5.8 v2] usb: dwc2: Add missing cleanups when usb_add_gadget_udc() fails Martin Blumenstingl
2020-07-04  5:58 ` Minas Harutyunyan
2020-07-26 10:04 ` Minas Harutyunyan
2020-07-27 17:35   ` Martin Blumenstingl

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git