diff mbox series

[net-next] net: phy: correctly check soft_reset ret ONLY if defined for PHY

Message ID 20231120131540.9442-1-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phy: correctly check soft_reset ret ONLY if defined for PHY | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/codegen success Generated files up to date
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1127 this patch: 1127
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1154 this patch: 1154
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1154 this patch: 1154
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Nov. 20, 2023, 1:15 p.m. UTC
soft_reset call for phy_init_hw had multiple revision across the years
and the implementation goes back to 2014. Originally was a simple call
to write the generic PHY reset BIT, it was then moved to a dedicated
function. It was then added the option for PHY driver to define their
own special way to reset the PHY. Till this change, checking for ret was
correct as it was always filled by either the generic reset or the
custom implementation. This changed tho with commit 6e2d85ec0559 ("net:
phy: Stop with excessive soft reset"), as the generic reset call to PHY
was dropped but the ret check was never made entirely optional and
dependent whether soft_reset was defined for the PHY driver or not.

Luckly nothing was ever added before the soft_reset call so the ret
check (in the case where a PHY didn't had soft_reset defined) although
wrong, never caused problems as ret was init 0 at the start of
phy_init_hw.

To prevent any kind of problem and to make the function cleaner and more
robust, correctly move the ret check if the soft_reset section making it
optional and needed only with the function defined.

Fixes: 6e2d85ec0559 ("net: phy: Stop with excessive soft reset")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phy_device.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Christian Marangi Nov. 20, 2023, 4:49 p.m. UTC | #1
On Mon, Nov 20, 2023 at 06:15:43PM +0100, Larysa Zaremba wrote:
> On Mon, Nov 20, 2023 at 02:15:40PM +0100, Christian Marangi wrote:
> > soft_reset call for phy_init_hw had multiple revision across the years
> > and the implementation goes back to 2014. Originally was a simple call
> > to write the generic PHY reset BIT, it was then moved to a dedicated
> > function. It was then added the option for PHY driver to define their
> > own special way to reset the PHY. Till this change, checking for ret was
> > correct as it was always filled by either the generic reset or the
> > custom implementation. This changed tho with commit 6e2d85ec0559 ("net:
> > phy: Stop with excessive soft reset"), as the generic reset call to PHY
> > was dropped but the ret check was never made entirely optional and
> > dependent whether soft_reset was defined for the PHY driver or not.
> > 
> > Luckly nothing was ever added before the soft_reset call so the ret
> > check (in the case where a PHY didn't had soft_reset defined) although
> > wrong, never caused problems as ret was init 0 at the start of
> > phy_init_hw.
> > 
> > To prevent any kind of problem and to make the function cleaner and more
> > robust, correctly move the ret check if the soft_reset section making it
> > optional and needed only with the function defined.
> > 
> > Fixes: 6e2d85ec0559 ("net: phy: Stop with excessive soft reset")
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/net/phy/phy_device.c | 9 ++++-----
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 2ce74593d6e4..478126f6b5bc 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -1235,14 +1235,13 @@ int phy_init_hw(struct phy_device *phydev)
> >  
> >  	if (phydev->drv->soft_reset) {
> >  		ret = phydev->drv->soft_reset(phydev);
> > +		if (ret < 0)
> > +			return ret;
> > +
> >  		/* see comment in genphy_soft_reset for an explanation */
> > -		if (!ret)
> > -			phydev->suspended = 0;
> > +		phydev->suspended = 0;
> 
> Are you sure 'suspended' should not be cleared, if soft_reset fails?
> 
> >  	}

Idea is not change current implementation... And before this, suspended
was cleared only with reset not failing.

> >  
> > -	if (ret < 0)
> > -		return ret;
> > -
> >  	ret = phy_scan_fixups(phydev);
> >  	if (ret < 0)
> >  		return ret;
> > -- 
> > 2.40.1
> > 
> >
Christian Marangi Nov. 20, 2023, 4:50 p.m. UTC | #2
On Mon, Nov 20, 2023 at 09:42:34AM -0800, Jakub Kicinski wrote:
> On Mon, 20 Nov 2023 14:15:40 +0100 Christian Marangi wrote:
> > Luckly nothing was ever added before the soft_reset call so the ret
> > check (in the case where a PHY didn't had soft_reset defined) although
> > wrong, never caused problems as ret was init 0 at the start of
> > phy_init_hw.
> 
> not currently a bug => no Fixes tag, please

I know it's not a bug but still the referenced commit was wrong. Can I
at least use Ref to reference it?

Due to the changes done to this function, it's hard to catch where the
problem arised with a git blame.
Larysa Zaremba Nov. 20, 2023, 5:15 p.m. UTC | #3
On Mon, Nov 20, 2023 at 02:15:40PM +0100, Christian Marangi wrote:
> soft_reset call for phy_init_hw had multiple revision across the years
> and the implementation goes back to 2014. Originally was a simple call
> to write the generic PHY reset BIT, it was then moved to a dedicated
> function. It was then added the option for PHY driver to define their
> own special way to reset the PHY. Till this change, checking for ret was
> correct as it was always filled by either the generic reset or the
> custom implementation. This changed tho with commit 6e2d85ec0559 ("net:
> phy: Stop with excessive soft reset"), as the generic reset call to PHY
> was dropped but the ret check was never made entirely optional and
> dependent whether soft_reset was defined for the PHY driver or not.
> 
> Luckly nothing was ever added before the soft_reset call so the ret
> check (in the case where a PHY didn't had soft_reset defined) although
> wrong, never caused problems as ret was init 0 at the start of
> phy_init_hw.
> 
> To prevent any kind of problem and to make the function cleaner and more
> robust, correctly move the ret check if the soft_reset section making it
> optional and needed only with the function defined.
> 
> Fixes: 6e2d85ec0559 ("net: phy: Stop with excessive soft reset")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
>  drivers/net/phy/phy_device.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 2ce74593d6e4..478126f6b5bc 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1235,14 +1235,13 @@ int phy_init_hw(struct phy_device *phydev)
>  
>  	if (phydev->drv->soft_reset) {
>  		ret = phydev->drv->soft_reset(phydev);
> +		if (ret < 0)
> +			return ret;
> +
>  		/* see comment in genphy_soft_reset for an explanation */
> -		if (!ret)
> -			phydev->suspended = 0;
> +		phydev->suspended = 0;

Are you sure 'suspended' should not be cleared, if soft_reset fails?

>  	}
>  
> -	if (ret < 0)
> -		return ret;
> -
>  	ret = phy_scan_fixups(phydev);
>  	if (ret < 0)
>  		return ret;
> -- 
> 2.40.1
> 
>
Jakub Kicinski Nov. 20, 2023, 5:42 p.m. UTC | #4
On Mon, 20 Nov 2023 14:15:40 +0100 Christian Marangi wrote:
> Luckly nothing was ever added before the soft_reset call so the ret
> check (in the case where a PHY didn't had soft_reset defined) although
> wrong, never caused problems as ret was init 0 at the start of
> phy_init_hw.

not currently a bug => no Fixes tag, please
Jakub Kicinski Nov. 20, 2023, 9:53 p.m. UTC | #5
On Mon, 20 Nov 2023 17:50:53 +0100 Christian Marangi wrote:
> On Mon, Nov 20, 2023 at 09:42:34AM -0800, Jakub Kicinski wrote:
> > On Mon, 20 Nov 2023 14:15:40 +0100 Christian Marangi wrote:  
> > > Luckly nothing was ever added before the soft_reset call so the ret
> > > check (in the case where a PHY didn't had soft_reset defined) although
> > > wrong, never caused problems as ret was init 0 at the start of
> > > phy_init_hw.  
> > 
> > not currently a bug => no Fixes tag, please  
> 
> I know it's not a bug but still the referenced commit was wrong. Can I
> at least use Ref to reference it?

Not sure what you mean by "Ref"

> Due to the changes done to this function, it's hard to catch where the
> problem arised with a git blame.

Right, and you already quote the commit in the body. No objections to
repeating that if you want, maybe:

Introduced by commit 6e2d85ec0559 ("net: phy: Stop with excessive soft
reset").

but as a part of the "body" of the commit message, not tags.
Larysa Zaremba Nov. 21, 2023, 9:09 a.m. UTC | #6
On Mon, Nov 20, 2023 at 05:49:28PM +0100, Christian Marangi wrote:
> On Mon, Nov 20, 2023 at 06:15:43PM +0100, Larysa Zaremba wrote:
> > On Mon, Nov 20, 2023 at 02:15:40PM +0100, Christian Marangi wrote:
> > > soft_reset call for phy_init_hw had multiple revision across the years
> > > and the implementation goes back to 2014. Originally was a simple call
> > > to write the generic PHY reset BIT, it was then moved to a dedicated
> > > function. It was then added the option for PHY driver to define their
> > > own special way to reset the PHY. Till this change, checking for ret was
> > > correct as it was always filled by either the generic reset or the
> > > custom implementation. This changed tho with commit 6e2d85ec0559 ("net:
> > > phy: Stop with excessive soft reset"), as the generic reset call to PHY
> > > was dropped but the ret check was never made entirely optional and
> > > dependent whether soft_reset was defined for the PHY driver or not.
> > > 
> > > Luckly nothing was ever added before the soft_reset call so the ret
> > > check (in the case where a PHY didn't had soft_reset defined) although
> > > wrong, never caused problems as ret was init 0 at the start of
> > > phy_init_hw.
> > > 
> > > To prevent any kind of problem and to make the function cleaner and more
> > > robust, correctly move the ret check if the soft_reset section making it
> > > optional and needed only with the function defined.
> > > 
> > > Fixes: 6e2d85ec0559 ("net: phy: Stop with excessive soft reset")
> > > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > > ---
> > >  drivers/net/phy/phy_device.c | 9 ++++-----
> > >  1 file changed, 4 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > > index 2ce74593d6e4..478126f6b5bc 100644
> > > --- a/drivers/net/phy/phy_device.c
> > > +++ b/drivers/net/phy/phy_device.c
> > > @@ -1235,14 +1235,13 @@ int phy_init_hw(struct phy_device *phydev)
> > >  
> > >  	if (phydev->drv->soft_reset) {
> > >  		ret = phydev->drv->soft_reset(phydev);
> > > +		if (ret < 0)
> > > +			return ret;
> > > +
> > >  		/* see comment in genphy_soft_reset for an explanation */
> > > -		if (!ret)
> > > -			phydev->suspended = 0;
> > > +		phydev->suspended = 0;
> > 
> > Are you sure 'suspended' should not be cleared, if soft_reset fails?
> > 
> > >  	}
> 
> Idea is not change current implementation... And before this, suspended
> was cleared only with reset not failing.
> 

Ah, OK. I should not do reviews that late.
If the change is purely cosmetic though, I think Fixes tag does not apply here.

Other than that:

Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com>

But I am also not certain, if maintainers would take such small of a change.

> > >  
> > > -	if (ret < 0)
> > > -		return ret;
> > > -
> > >  	ret = phy_scan_fixups(phydev);
> > >  	if (ret < 0)
> > >  		return ret;
> > > -- 
> > > 2.40.1
> > > 
> > > 
> 
> -- 
> 	Ansuel
>
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2ce74593d6e4..478126f6b5bc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1235,14 +1235,13 @@  int phy_init_hw(struct phy_device *phydev)
 
 	if (phydev->drv->soft_reset) {
 		ret = phydev->drv->soft_reset(phydev);
+		if (ret < 0)
+			return ret;
+
 		/* see comment in genphy_soft_reset for an explanation */
-		if (!ret)
-			phydev->suspended = 0;
+		phydev->suspended = 0;
 	}
 
-	if (ret < 0)
-		return ret;
-
 	ret = phy_scan_fixups(phydev);
 	if (ret < 0)
 		return ret;