]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: phy: fix phy_read_poll_timeout argument type in genphy_loopback
authorNikita Kiryushin <kiryushin@ancud.ru>
Fri, 15 Mar 2024 17:50:52 +0000 (20:50 +0300)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:17:36 +0000 (18:17 -0400)
[ Upstream commit 32fa4366cc4da1c97b725a0066adf43c6b298f37 ]

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>
Link: https://lore.kernel.org/r/20240315175052.8049-1-kiryushin@ancud.ru
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/phy/phy_device.c

index 3ad9bbf65cbeb0797c0c96a2f79c5e28c95a41e7..6125418ca93f31f1e60b5d7c4a009690b2989fd1 100644 (file)
@@ -2706,8 +2706,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);