]> git.itanic.dy.fi Git - linux-stable/commit
net: phylib: fix phy_read*_poll_timeout()
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thu, 1 Jun 2023 15:48:12 +0000 (16:48 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 3 Jun 2023 06:20:31 +0000 (23:20 -0700)
commit4ec7329517027db28c5683675ab3b3842ad60324
treef9c7a2a10fb4382cce7af183fa7e8dd46a3895ad
parent7fa217d4be0fd6f4f91e01ab7c4a7f225462e013
net: phylib: fix phy_read*_poll_timeout()

Dan Carpenter reported a signedness bug in genphy_loopback(). Andrew
reports that:

"It is common to get this wrong in general with PHY drivers. Dan
regularly posts fixes like this soon after a PHY driver patch it
merged. I really wish we could somehow get the compiler to warn when
the result from phy_read() is stored into a unsigned type. It would
save Dan a lot of work."

Let's make phy_read*_poll_timeout() immune to further issues when "val"
is an unsigned type by storing the read function's result in a signed
int as well as "val", and using the signed variable both to check for
an error and for propagating that error to the caller.

The advantage of this method is we don't change where the cast from
the signed return code to the user's variable occurs - so users will
see no change.

Previously Heiner changed phy_read_poll_timeout() to check for an error
before evaluating the user supplied condition, but didn't update
phy_read_mmd_poll_timeout(). Make that change there too.

Link: https://lore.kernel.org/r/d7bb312e-2428-45f6-b9b3-59ba544e8b94@kili.mountain
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/E1q4kX6-00BNuM-Mx@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/phy.h