linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: chipidea: add a check for the availability of next child
@ 2018-12-26 18:36 Kangjie Lu
  2018-12-27  0:43 ` Peter Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2018-12-26 18:36 UTC (permalink / raw)
  To: kjlu; +Cc: pakki001, Peter Chen, Greg Kroah-Hartman, linux-usb, linux-kernel

of_get_next_available_child returns NULL when no child nodes are found.
The fix checks its return value instead of assuming a child is found.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/usb/chipidea/ci_hdrc_msm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c
index 880009987460..b7f7acef72d4 100644
--- a/drivers/usb/chipidea/ci_hdrc_msm.c
+++ b/drivers/usb/chipidea/ci_hdrc_msm.c
@@ -250,6 +250,10 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	ulpi_node = of_get_child_by_name(pdev->dev.of_node, "ulpi");
 	if (ulpi_node) {
 		phy_node = of_get_next_available_child(ulpi_node, NULL);
+		if (!phy_node) {
+			dev_err(&pdev->dev, "no child nodes found\n");
+			return -ENODEV;
+		}
 		ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
 		of_node_put(phy_node);
 	}
-- 
2.17.2 (Apple Git-113)


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

* RE: [PATCH v2] usb: chipidea: add a check for the availability of next child
  2018-12-26 18:36 [PATCH v2] usb: chipidea: add a check for the availability of next child Kangjie Lu
@ 2018-12-27  0:43 ` Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2018-12-27  0:43 UTC (permalink / raw)
  To: Kangjie Lu; +Cc: pakki001, Greg Kroah-Hartman, linux-usb, linux-kernel

 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/usb/chipidea/ci_hdrc_msm.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c
> b/drivers/usb/chipidea/ci_hdrc_msm.c
> index 880009987460..b7f7acef72d4 100644
> --- a/drivers/usb/chipidea/ci_hdrc_msm.c
> +++ b/drivers/usb/chipidea/ci_hdrc_msm.c
> @@ -250,6 +250,10 @@ static int ci_hdrc_msm_probe(struct platform_device
> *pdev)
>  	ulpi_node = of_get_child_by_name(pdev->dev.of_node, "ulpi");
>  	if (ulpi_node) {
>  		phy_node = of_get_next_available_child(ulpi_node, NULL);
> +		if (!phy_node) {
> +			dev_err(&pdev->dev, "no child nodes found\n");
> +			return -ENODEV;
> +		}

There are still two issues for this patch:
- It can't return -ENODEV directly, instead, it needs to goto err_mux
- Before goto err_mux, it needs to call of_node_put(ulpi_node);

Besides, for kernel code style, you may leave one blank line after if () {} statement.

Peter

>  		ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
>  		of_node_put(phy_node);
>  	}
> --
> 2.17.2 (Apple Git-113)


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

* RE: [PATCH] [V2] usb: chipidea: add a check for the availability of next child
  2019-01-05 15:58 [PATCH] [V2] " Aditya Pakki
@ 2019-01-07  2:06 ` Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-01-07  2:06 UTC (permalink / raw)
  To: Aditya Pakki; +Cc: kjlu, Greg Kroah-Hartman, linux-usb, linux-kernel

 
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c
> b/drivers/usb/chipidea/ci_hdrc_msm.c
> index 880009987460..813673eee815 100644
> --- a/drivers/usb/chipidea/ci_hdrc_msm.c
> +++ b/drivers/usb/chipidea/ci_hdrc_msm.c
> @@ -250,6 +250,10 @@ static int ci_hdrc_msm_probe(struct platform_device
> *pdev)
>  	ulpi_node = of_get_child_by_name(pdev->dev.of_node, "ulpi");
>  	if (ulpi_node) {
>  		phy_node = of_get_next_available_child(ulpi_node, NULL);
> +		if (!phy_node) {
> +			ret = -EINVAL;
> +			goto err_mux;
> +		}

You may need to call of_node_put(ulpi_node) before goto, I commented it before.

Peter

>  		ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
>  		of_node_put(phy_node);
>  	}
> --
> 2.17.1


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

* [PATCH] [V2] usb: chipidea: add a check for the availability of next child
@ 2019-01-05 15:58 Aditya Pakki
  2019-01-07  2:06 ` Peter Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Aditya Pakki @ 2019-01-05 15:58 UTC (permalink / raw)
  To: pakki001; +Cc: kjlu, Peter Chen, Greg Kroah-Hartman, linux-usb, linux-kernel

of_get_next_available_child returns NULL when no child nodes are found.
The fix checks its return value instead of assuming a child is found.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/usb/chipidea/ci_hdrc_msm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c
index 880009987460..813673eee815 100644
--- a/drivers/usb/chipidea/ci_hdrc_msm.c
+++ b/drivers/usb/chipidea/ci_hdrc_msm.c
@@ -250,6 +250,10 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	ulpi_node = of_get_child_by_name(pdev->dev.of_node, "ulpi");
 	if (ulpi_node) {
 		phy_node = of_get_next_available_child(ulpi_node, NULL);
+		if (!phy_node) {
+			ret = -EINVAL;
+			goto err_mux;
+		}
 		ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
 		of_node_put(phy_node);
 	}
-- 
2.17.1


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

end of thread, other threads:[~2019-01-07  2:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-26 18:36 [PATCH v2] usb: chipidea: add a check for the availability of next child Kangjie Lu
2018-12-27  0:43 ` Peter Chen
2019-01-05 15:58 [PATCH] [V2] " Aditya Pakki
2019-01-07  2:06 ` Peter Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).