linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
@ 2024-03-14 11:15 Nikita Kiryushin
  2024-03-14 23:48 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Nikita Kiryushin @ 2024-03-14 11:15 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Oleksij Rempel, netdev,
	linux-kernel, lvc-project


read_poll_timeout inside phy_read_poll_timeout can set val negative
in some cases (for example, __mdiobus_read inside phy_read can return
-EOPNOTSUPP).

Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
should fix problems with wrong-signed vals, but I do not see how
as val is sent to phy_read as is and __val = phy_read (not val)
is checked for sign.

Change val type for signed to allow better error handling as done in other
phy_read_poll_timeout callers. This will not fix any error handling
by itself, but allows, for example, to modify cond with appropriate
sign check or check resulting val separately.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 014068dcb5b1 ("net: phy: genphy_loopback: add link speed configuration")
Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
---
  drivers/net/phy/phy_device.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 8297ef681bf5..6c6ec9475709 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2831,8 +2831,8 @@ EXPORT_SYMBOL(genphy_resume);
  int genphy_loopback(struct phy_device *phydev, bool enable)
  {
  	if (enable) {
-		u16 val, ctl = BMCR_LOOPBACK;
-		int ret;
+		u16 ctl = BMCR_LOOPBACK;
+		int ret, val;
  
  		ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
  
-- 
2.34.1


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

* Re: [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
  2024-03-14 11:15 [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback Nikita Kiryushin
@ 2024-03-14 23:48 ` Jakub Kicinski
  2024-03-15 17:50   ` Nikita Kiryushin
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2024-03-14 23:48 UTC (permalink / raw)
  To: Nikita Kiryushin
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Paolo Abeni, Oleksij Rempel, netdev, linux-kernel,
	lvc-project

On Thu, 14 Mar 2024 14:15:37 +0300 Nikita Kiryushin wrote:
> read_poll_timeout inside phy_read_poll_timeout can set val negative
> in some cases (for example, __mdiobus_read inside phy_read can return
> -EOPNOTSUPP).
> 
> Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
> should fix problems with wrong-signed vals, but I do not see how
> as val is sent to phy_read as is and __val = phy_read (not val)
> is checked for sign.
> 
> Change val type for signed to allow better error handling as done in other
> phy_read_poll_timeout callers. This will not fix any error handling
> by itself, but allows, for example, to modify cond with appropriate
> sign check or check resulting val separately.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 014068dcb5b1 ("net: phy: genphy_loopback: add link speed configuration")
> Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>

Please use git send email, the patch is mangled.
-- 
pw-bot: cr

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

* [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
  2024-03-14 23:48 ` Jakub Kicinski
@ 2024-03-15 17:50   ` Nikita Kiryushin
  2024-03-15 18:38     ` Russell King (Oracle)
  2024-03-19 15:20     ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Nikita Kiryushin @ 2024-03-15 17:50 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Nikita Kiryushin, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Oleksij Rempel,
	netdev, linux-kernel, lvc-project

read_poll_timeout inside phy_read_poll_timeout can set val negative
in some cases (for example, __mdiobus_read inside phy_read can return
-EOPNOTSUPP).

Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
should fix problems with wrong-signed vals, but I do not see how
as val is sent to phy_read as is and __val = phy_read (not val)
is checked for sign.

Change val type for signed to allow better error handling as done in other
phy_read_poll_timeout callers. This will not fix any error handling
by itself, but allows, for example, to modify cond with appropriate
sign check or check resulting val separately.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 014068dcb5b1 ("net: phy: genphy_loopback: add link speed configuration")
Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
---
 drivers/net/phy/phy_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 8297ef681bf5..6c6ec9475709 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2831,8 +2831,8 @@ EXPORT_SYMBOL(genphy_resume);
 int genphy_loopback(struct phy_device *phydev, bool enable)
 {
 	if (enable) {
-		u16 val, ctl = BMCR_LOOPBACK;
-		int ret;
+		u16 ctl = BMCR_LOOPBACK;
+		int ret, val;
 
 		ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
 
-- 
2.34.1


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

* Re: [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
  2024-03-15 17:50   ` Nikita Kiryushin
@ 2024-03-15 18:38     ` Russell King (Oracle)
  2024-03-19 15:20     ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2024-03-15 18:38 UTC (permalink / raw)
  To: Nikita Kiryushin
  Cc: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Oleksij Rempel, netdev,
	linux-kernel, lvc-project

On Fri, Mar 15, 2024 at 08:50:52PM +0300, Nikita Kiryushin wrote:
> read_poll_timeout inside phy_read_poll_timeout can set val negative
> in some cases (for example, __mdiobus_read inside phy_read can return
> -EOPNOTSUPP).
> 
> Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
> should fix problems with wrong-signed vals, but I do not see how
> as val is sent to phy_read as is and __val = phy_read (not val)
> is checked for sign.
> 
> Change val type for signed to allow better error handling as done in other
> phy_read_poll_timeout callers. This will not fix any error handling
> by itself, but allows, for example, to modify cond with appropriate
> sign check or check resulting val separately.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 014068dcb5b1 ("net: phy: genphy_loopback: add link speed configuration")
> Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
  2024-03-15 17:50   ` Nikita Kiryushin
  2024-03-15 18:38     ` Russell King (Oracle)
@ 2024-03-19 15:20     ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-19 15:20 UTC (permalink / raw)
  To: Nikita Kiryushin
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	o.rempel, netdev, linux-kernel, lvc-project

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Fri, 15 Mar 2024 20:50:52 +0300 you wrote:
> read_poll_timeout inside phy_read_poll_timeout can set val negative
> in some cases (for example, __mdiobus_read inside phy_read can return
> -EOPNOTSUPP).
> 
> Supposedly, commit 4ec732951702 ("net: phylib: fix phy_read*_poll_timeout()")
> should fix problems with wrong-signed vals, but I do not see how
> as val is sent to phy_read as is and __val = phy_read (not val)
> is checked for sign.
> 
> [...]

Here is the summary with links:
  - [net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
    https://git.kernel.org/netdev/net/c/32fa4366cc4d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-03-19 15:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14 11:15 [PATCH net] net: phy: fix phy_read_poll_timeout argument type in genphy_loopback Nikita Kiryushin
2024-03-14 23:48 ` Jakub Kicinski
2024-03-15 17:50   ` Nikita Kiryushin
2024-03-15 18:38     ` Russell King (Oracle)
2024-03-19 15:20     ` patchwork-bot+netdevbpf

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).