Patchwork [V2] usb: chipidea: add a check for the availability of next child

login
register
mail settings
Submitter Aditya Pakki
Date Jan. 5, 2019, 3:58 p.m.
Message ID <20190105155847.3091-1-pakki001@umn.edu>
Download mbox | patch
Permalink /patch/693357/
State New
Headers show

Comments

Aditya Pakki - Jan. 5, 2019, 3:58 p.m.
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(+)
Peter Chen - Jan. 7, 2019, 2:06 a.m.
> 
> 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

Patch

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);
 	}