Message ID | 20210914143026.2.I38b706ca6f52e86cb791245a2aee6a81fbd1c030@changeid |
---|---|
State | Accepted |
Commit | 5d81616fb8f30f9ea16d2f32ab7365296f2ae886 |
Delegated to: | Patrice Chotard |
Headers | show |
Series | [1/2] phy: stm32-usbphyc: use connector for vbus-supply with phy-stm32-usbphyc | expand |
HI Patrick On 9/14/21 2:31 PM, Patrick Delaunay wrote: > Add protection on presence and order of the phy node sub node > by using the mandatory reg information. > > Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> > --- > > drivers/phy/phy-stm32-usbphyc.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c > index c206efd28d..9c1dcfae52 100644 > --- a/drivers/phy/phy-stm32-usbphyc.c > +++ b/drivers/phy/phy-stm32-usbphyc.c > @@ -340,7 +340,7 @@ static int stm32_usbphyc_probe(struct udevice *dev) > struct stm32_usbphyc *usbphyc = dev_get_priv(dev); > struct reset_ctl reset; > ofnode node, connector; > - int i, ret; > + int ret; > > usbphyc->base = dev_read_addr(dev); > if (usbphyc->base == FDT_ADDR_T_NONE) > @@ -378,14 +378,18 @@ static int stm32_usbphyc_probe(struct udevice *dev) > return ret; > } > > - /* > - * parse all PHY subnodes in order to populate regulator associated > - * to each PHY port > - */ > - node = dev_read_first_subnode(dev); > - for (i = 0; i < MAX_PHYS; i++) { > - struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + i; > + /* parse all PHY subnodes to populate regulator associated to each PHY port */ > + dev_for_each_subnode(node, dev) { > + fdt_addr_t phy_id; > + struct stm32_usbphyc_phy *usbphyc_phy; > > + phy_id = ofnode_read_u32_default(node, "reg", FDT_ADDR_T_NONE); > + if (phy_id >= MAX_PHYS) { > + dev_err(dev, "invalid reg value %lx for %s\n", > + phy_id, ofnode_get_name(node)); > + return -ENOENT; > + } > + usbphyc_phy = usbphyc->phys + phy_id; > usbphyc_phy->init = false; > usbphyc_phy->powered = false; > ret = stm32_usbphyc_get_regulator(node, "phy-supply", > @@ -401,8 +405,6 @@ static int stm32_usbphyc_probe(struct udevice *dev) > ret = stm32_usbphyc_get_regulator(connector, "vbus-supply", > &usbphyc_phy->vbus); > } > - > - node = dev_read_next_subnode(node); > } > > /* Check if second port has to be used for host controller */ > Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com> Thanks Patrice
diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c index c206efd28d..9c1dcfae52 100644 --- a/drivers/phy/phy-stm32-usbphyc.c +++ b/drivers/phy/phy-stm32-usbphyc.c @@ -340,7 +340,7 @@ static int stm32_usbphyc_probe(struct udevice *dev) struct stm32_usbphyc *usbphyc = dev_get_priv(dev); struct reset_ctl reset; ofnode node, connector; - int i, ret; + int ret; usbphyc->base = dev_read_addr(dev); if (usbphyc->base == FDT_ADDR_T_NONE) @@ -378,14 +378,18 @@ static int stm32_usbphyc_probe(struct udevice *dev) return ret; } - /* - * parse all PHY subnodes in order to populate regulator associated - * to each PHY port - */ - node = dev_read_first_subnode(dev); - for (i = 0; i < MAX_PHYS; i++) { - struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + i; + /* parse all PHY subnodes to populate regulator associated to each PHY port */ + dev_for_each_subnode(node, dev) { + fdt_addr_t phy_id; + struct stm32_usbphyc_phy *usbphyc_phy; + phy_id = ofnode_read_u32_default(node, "reg", FDT_ADDR_T_NONE); + if (phy_id >= MAX_PHYS) { + dev_err(dev, "invalid reg value %lx for %s\n", + phy_id, ofnode_get_name(node)); + return -ENOENT; + } + usbphyc_phy = usbphyc->phys + phy_id; usbphyc_phy->init = false; usbphyc_phy->powered = false; ret = stm32_usbphyc_get_regulator(node, "phy-supply", @@ -401,8 +405,6 @@ static int stm32_usbphyc_probe(struct udevice *dev) ret = stm32_usbphyc_get_regulator(connector, "vbus-supply", &usbphyc_phy->vbus); } - - node = dev_read_next_subnode(node); } /* Check if second port has to be used for host controller */
Add protection on presence and order of the phy node sub node by using the mandatory reg information. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> --- drivers/phy/phy-stm32-usbphyc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)