mbox series

[00/11] usb: dwc3: various cleanups

Message ID 20240814-b4-cleanup-h-of-node-put-usb-v1-0-95481b9682bc@linaro.org
Headers show
Series usb: dwc3: various cleanups | expand

Message

Krzysztof Kozlowski Aug. 14, 2024, 10:35 a.m. UTC
Hi,

The first ST patch depends on my fix:
https://lore.kernel.org/all/20240814093957.37940-2-krzysztof.kozlowski@linaro.org/

Series makes some code simplifications and cleanups.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (11):
      usb: dwc3: st: use scoped device node handling to simplify error paths
      usb: dwc3: st: simplify with dev_err_probe
      usb: dwc3: st: simplify pdev->dev usage
      usb: dwc3: imx8mp: simplify with devm_clk_get_enabled
      usb: dwc3: imx8mp: simplify with dev_err_probe
      usb: dwc3: imx8mp: use scoped device node handling to simplify error paths
      usb: dwc3: qcom: use scoped device node handling to simplify error paths
      usb: dwc3: qcom: simplify with devm_platform_ioremap_resource
      usb: dwc3: rtk: use scoped device node handling to simplify error paths
      usb: dwc3: rtk: return directly and simplify with devm_platform_ioremap_resource
      usb: dwc3: xilinx: simplify with dev_err_probe

 drivers/usb/dwc3/dwc3-imx8mp.c | 66 ++++++++++++------------------------------
 drivers/usb/dwc3/dwc3-qcom.c   | 16 ++++------
 drivers/usb/dwc3/dwc3-rtk.c    | 52 ++++++++++-----------------------
 drivers/usb/dwc3/dwc3-st.c     | 38 +++++++++++-------------
 drivers/usb/dwc3/dwc3-xilinx.c |  7 ++---
 5 files changed, 58 insertions(+), 121 deletions(-)
---
base-commit: 64b429eaf21be888cc83e9013e25897d5fb03a75
change-id: 20240814-b4-cleanup-h-of-node-put-usb-93fadfc77d33

Best regards,

Comments

Patrice CHOTARD Aug. 14, 2024, 3:43 p.m. UTC | #1
On 8/14/24 12:35, Krzysztof Kozlowski wrote:
> Obtain the device node reference with scoped/cleanup.h to reduce error
> handling and make the code a bit simpler.  Scoped/cleanup.h coding style
> expects variable declaration with initialization, so the
> of_get_compatible_child() call has to be moved earlier, before any goto
> jumps happen.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> ---
> 
> This depends on my earlier fix:
> https://lore.kernel.org/all/20240814093957.37940-2-krzysztof.kozlowski@linaro.org/
> ---
>  drivers/usb/dwc3/dwc3-st.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
> index c8c7cd0c1796..98f43d7082d7 100644
> --- a/drivers/usb/dwc3/dwc3-st.c
> +++ b/drivers/usb/dwc3/dwc3-st.c
> @@ -14,6 +14,7 @@
>   * Inspired by dwc3-omap.c and dwc3-exynos.c.
>   */
>  
> +#include <linux/cleanup.h>
>  #include <linux/delay.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
> @@ -197,7 +198,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	struct st_dwc3 *dwc3_data;
>  	struct resource *res;
>  	struct device *dev = &pdev->dev;
> -	struct device_node *node = dev->of_node, *child;
> +	struct device_node *node = dev->of_node;
>  	struct platform_device *child_pdev;
>  	struct regmap *regmap;
>  	int ret;
> @@ -227,6 +228,13 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	dev_vdbg(&pdev->dev, "glue-logic addr 0x%pK, syscfg-reg offset 0x%x\n",
>  		 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
>  
> +	struct device_node *child __free(device_node) = of_get_compatible_child(node,
> +										"snps,dwc3");
> +	if (!child) {
> +		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
> +		return -ENODEV;
> +	}
> +
>  	dwc3_data->rstc_pwrdn =
>  		devm_reset_control_get_exclusive(dev, "powerdown");
>  	if (IS_ERR(dwc3_data->rstc_pwrdn)) {
> @@ -248,18 +256,11 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	/* Manage SoftReset */
>  	reset_control_deassert(dwc3_data->rstc_rst);
>  
> -	child = of_get_compatible_child(node, "snps,dwc3");
> -	if (!child) {
> -		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
> -		ret = -ENODEV;
> -		goto err_node_put;
> -	}
> -
>  	/* Allocate and initialize the core */
>  	ret = of_platform_populate(node, NULL, NULL, dev);
>  	if (ret) {
>  		dev_err(dev, "failed to add dwc3 core\n");
> -		goto err_node_put;
> +		goto undo_softreset;
>  	}
>  
>  	child_pdev = of_find_device_by_node(child);
> @@ -270,7 +271,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	}
>  
>  	dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
> -	of_node_put(child);
>  	platform_device_put(child_pdev);
>  
>  	/*
> @@ -282,8 +282,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	ret = st_dwc3_drd_init(dwc3_data);
>  	if (ret) {
>  		dev_err(dev, "drd initialisation failed\n");
> -		of_platform_depopulate(dev);
> -		goto undo_softreset;
> +		goto depopulate;
>  	}
>  
>  	/* ST glue logic init */
> @@ -294,8 +293,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  
>  depopulate:
>  	of_platform_depopulate(dev);
> -err_node_put:
> -	of_node_put(child);
>  undo_softreset:
>  	reset_control_assert(dwc3_data->rstc_rst);
>  undo_powerdown:
> 


Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
Thinh Nguyen Aug. 27, 2024, 1:59 a.m. UTC | #2
Hi Krzysztof,

On Wed, Aug 14, 2024, Krzysztof Kozlowski wrote:
> Hi,
> 
> The first ST patch depends on my fix:
> https://urldefense.com/v3/__https://lore.kernel.org/all/20240814093957.37940-2-krzysztof.kozlowski@linaro.org/__;!!A4F2R9G_pg!eFzt54pYSEl8wrvrH7yQSwFRzbojnRSyelnYjxlY8RZaU6oZCVeui2f-DHQ0bk8Fdy6gvJoSWLeAPz2w_3F9ownOFLGUoyHd$ 
> 
> Series makes some code simplifications and cleanups.
> 
> Best regards,
> Krzysztof
> 
> ---
> Krzysztof Kozlowski (11):
>       usb: dwc3: st: use scoped device node handling to simplify error paths
>       usb: dwc3: st: simplify with dev_err_probe
>       usb: dwc3: st: simplify pdev->dev usage
>       usb: dwc3: imx8mp: simplify with devm_clk_get_enabled
>       usb: dwc3: imx8mp: simplify with dev_err_probe
>       usb: dwc3: imx8mp: use scoped device node handling to simplify error paths
>       usb: dwc3: qcom: use scoped device node handling to simplify error paths
>       usb: dwc3: qcom: simplify with devm_platform_ioremap_resource
>       usb: dwc3: rtk: use scoped device node handling to simplify error paths
>       usb: dwc3: rtk: return directly and simplify with devm_platform_ioremap_resource
>       usb: dwc3: xilinx: simplify with dev_err_probe
> 
>  drivers/usb/dwc3/dwc3-imx8mp.c | 66 ++++++++++++------------------------------
>  drivers/usb/dwc3/dwc3-qcom.c   | 16 ++++------
>  drivers/usb/dwc3/dwc3-rtk.c    | 52 ++++++++++-----------------------
>  drivers/usb/dwc3/dwc3-st.c     | 38 +++++++++++-------------
>  drivers/usb/dwc3/dwc3-xilinx.c |  7 ++---
>  5 files changed, 58 insertions(+), 121 deletions(-)
> ---
> base-commit: 64b429eaf21be888cc83e9013e25897d5fb03a75
> change-id: 20240814-b4-cleanup-h-of-node-put-usb-93fadfc77d33
> 
> Best regards,
> -- 
> Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 

Thanks for the cleanup!

I wish the mixed declarations in between statements for some of the
scoped device node handling can be changed. Bugs me a little with how
I'm used to parse the old standard with my eyes, but it's not a big
issue.

BR,
Thinh
Krzysztof Kozlowski Aug. 27, 2024, 9:36 a.m. UTC | #3
On 27/08/2024 03:59, Thinh Nguyen wrote:
> Hi Krzysztof,
> 
> On Wed, Aug 14, 2024, Krzysztof Kozlowski wrote:
>> Hi,
>>
>> The first ST patch depends on my fix:
>> https://urldefense.com/v3/__https://lore.kernel.org/all/20240814093957.37940-2-krzysztof.kozlowski@linaro.org/__;!!A4F2R9G_pg!eFzt54pYSEl8wrvrH7yQSwFRzbojnRSyelnYjxlY8RZaU6oZCVeui2f-DHQ0bk8Fdy6gvJoSWLeAPz2w_3F9ownOFLGUoyHd$ 
>>
>> Series makes some code simplifications and cleanups.
>>
>> Best regards,
>> Krzysztof
>>
>> ---
>> Krzysztof Kozlowski (11):
>>       usb: dwc3: st: use scoped device node handling to simplify error paths
>>       usb: dwc3: st: simplify with dev_err_probe
>>       usb: dwc3: st: simplify pdev->dev usage
>>       usb: dwc3: imx8mp: simplify with devm_clk_get_enabled
>>       usb: dwc3: imx8mp: simplify with dev_err_probe
>>       usb: dwc3: imx8mp: use scoped device node handling to simplify error paths
>>       usb: dwc3: qcom: use scoped device node handling to simplify error paths
>>       usb: dwc3: qcom: simplify with devm_platform_ioremap_resource
>>       usb: dwc3: rtk: use scoped device node handling to simplify error paths
>>       usb: dwc3: rtk: return directly and simplify with devm_platform_ioremap_resource
>>       usb: dwc3: xilinx: simplify with dev_err_probe
>>
>>  drivers/usb/dwc3/dwc3-imx8mp.c | 66 ++++++++++++------------------------------
>>  drivers/usb/dwc3/dwc3-qcom.c   | 16 ++++------
>>  drivers/usb/dwc3/dwc3-rtk.c    | 52 ++++++++++-----------------------
>>  drivers/usb/dwc3/dwc3-st.c     | 38 +++++++++++-------------
>>  drivers/usb/dwc3/dwc3-xilinx.c |  7 ++---
>>  5 files changed, 58 insertions(+), 121 deletions(-)
>> ---
>> base-commit: 64b429eaf21be888cc83e9013e25897d5fb03a75
>> change-id: 20240814-b4-cleanup-h-of-node-put-usb-93fadfc77d33
>>
>> Best regards,
>> -- 
>> Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
> 
> Thanks for the cleanup!
> 
> I wish the mixed declarations in between statements for some of the
> scoped device node handling can be changed. Bugs me a little with how
> I'm used to parse the old standard with my eyes, but it's not a big
> issue.

Maybe this will be helpful:


https://lore.kernel.org/all/CAHk-=wicfvWPuRVDG5R1mZSxD8Xg=-0nLOiHay2T_UJ0yDX42g@mail.gmail.com/

https://lore.kernel.org/all/CAHk-=wgRHiV5VSxtfXA4S6aLUmcQYEuB67u3BJPJPtuESs1JyA@mail.gmail.com/

https://lore.kernel.org/all/CAHk-=whvOGL3aNhtps0YksGtzvaob_bvZpbaTcVEqGwNMxB6xg@mail.gmail.com/

and finally it will reach documentation (although it focuses on
unwinding process to be specific - "When the unwind order ..."):
https://lore.kernel.org/all/171175585714.2192972.12661675876300167762.stgit@dwillia2-xfh.jf.intel.com/

Best regards,
Krzysztof