2022-08-22 10:47:53

by Peter Geis

[permalink] [raw]
Subject: [PATCH] phy: rockchip-inno-usb2: Return zero after otg sync

The otg sync state patch reuses the ret variable, but fails to set it to
zero after use. This leads to a situation when the otg port is in
peripheral mode where the otg phy aborts halfway through setup. Fix this
by setting ret to zero after use.

Fixes: 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")

Reported-by: Markus Reichl <[email protected]>
Reported-by: Michael Riesch <[email protected]>
Signed-off-by: Peter Geis <[email protected]>
Tested-by: Michael Riesch <[email protected]>
Tested-by: Markus Reichl <[email protected]>
---
drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 0b1e9337ee8e..5fc7c374a6b4 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -1169,6 +1169,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
/* do initial sync of usb state */
ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
+ ret = 0;
}
}

--
2.25.1


2022-08-23 04:15:31

by Samuel Holland

[permalink] [raw]
Subject: Re: [PATCH] phy: rockchip-inno-usb2: Return zero after otg sync

On 8/22/22 5:32 AM, Peter Geis wrote:
> The otg sync state patch reuses the ret variable, but fails to set it to
> zero after use. This leads to a situation when the otg port is in
> peripheral mode where the otg phy aborts halfway through setup. Fix this
> by setting ret to zero after use.
>
> Fixes: 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")
>
> Reported-by: Markus Reichl <[email protected]>
> Reported-by: Michael Riesch <[email protected]>
> Signed-off-by: Peter Geis <[email protected]>
> Tested-by: Michael Riesch <[email protected]>
> Tested-by: Markus Reichl <[email protected]>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 0b1e9337ee8e..5fc7c374a6b4 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -1169,6 +1169,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
> /* do initial sync of usb state */
> ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
> extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
> + ret = 0;

The bug was caused by the unexpected consequence of (mis|re)using the "ret"
variable for a temporary value. Please introduce a new variable here, else the
use of "ret" is even more confusing. This code also wipes out any error returned
by devm_extcon_register_notifier().

Regards,
Samuel

2022-08-23 06:19:33

by Peter Geis

[permalink] [raw]
Subject: Re: [PATCH] phy: rockchip-inno-usb2: Return zero after otg sync

On Tue, Aug 23, 2022 at 5:41 AM Samuel Holland <[email protected]> wrote:
>
> On 8/22/22 5:32 AM, Peter Geis wrote:
> > The otg sync state patch reuses the ret variable, but fails to set it to
> > zero after use. This leads to a situation when the otg port is in
> > peripheral mode where the otg phy aborts halfway through setup. Fix this
> > by setting ret to zero after use.
> >
> > Fixes: 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")
> >
> > Reported-by: Markus Reichl <[email protected]>
> > Reported-by: Michael Riesch <[email protected]>
> > Signed-off-by: Peter Geis <[email protected]>
> > Tested-by: Michael Riesch <[email protected]>
> > Tested-by: Markus Reichl <[email protected]>
> > ---
> > drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> > index 0b1e9337ee8e..5fc7c374a6b4 100644
> > --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> > +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> > @@ -1169,6 +1169,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
> > /* do initial sync of usb state */
> > ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
> > extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
> > + ret = 0;
>
> The bug was caused by the unexpected consequence of (mis|re)using the "ret"
> variable for a temporary value. Please introduce a new variable here, else the
> use of "ret" is even more confusing. This code also wipes out any error returned
> by devm_extcon_register_notifier().

I see your point here, I also need to skip this if
devm_extcon_register_notifier() fails as well. I'll spin up a v2.

Thanks for catching that!

>
> Regards,
> Samuel

2022-08-23 14:59:51

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH] phy: rockchip-inno-usb2: Return zero after otg sync

Am Montag, 22. August 2022, 12:32:18 CEST schrieb Peter Geis:
> The otg sync state patch reuses the ret variable, but fails to set it to
> zero after use. This leads to a situation when the otg port is in
> peripheral mode where the otg phy aborts halfway through setup. Fix this
> by setting ret to zero after use.
>
> Fixes: 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")
>
> Reported-by: Markus Reichl <[email protected]>
> Reported-by: Michael Riesch <[email protected]>
> Signed-off-by: Peter Geis <[email protected]>
> Tested-by: Michael Riesch <[email protected]>
> Tested-by: Markus Reichl <[email protected]>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 0b1e9337ee8e..5fc7c374a6b4 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -1169,6 +1169,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
> /* do initial sync of usb state */
> ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
> extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
> + ret = 0;
> }
> }

I also ran into that issue just now :-) .
So am looking forward to v2.

Thanks
Heiko