Skip to content

net: dsa: mt7530: fix swallowed MDIO read errors

Daniel Golle linux-arm-kernel linux-mediatek lkml netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 3 repliesIn review
  2. v13 patches 3 repliesApplied 3/3

Changes in v2 from the cover letter

* 1/4: also check the identical unchecked bus->read() in core_rmw(), and fix mtk_pcs_lynxi_get_state() (drivers/net/pcs/pcs-mtk-lynxi.c) to check regmap_read() now that a failed read can leave its output unwritten instead of holding truncated-but-defined garbage
* 2/4: drop the redundant regmap_read() after regmap_read_poll_timeout(), and print ret in the error messages
* 3/4: also check mt7530_mii_write()'s return for the PHY_IAC command word in all four PHY access helpers, and print ret in the poll error messages
* add 4/4, calling mt7530_mutex_lock()/unlock() around the regmap IRQ chip's own accesses via handle_pre_irq/handle_post_irq/ handle_mask_sync, the same driver-provided locking every other user of the unlocked switch regmap already goes through, instead of adding a second regmap instance

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state()drivers/net/pcs/pcs-mtk-lynxi.c+3 -21 reply
2/5net: dsa: mt7530: check bus->read() errors in the MDIO regmap backenddrivers/net/dsa/mt7530-mdio.c drivers/net/dsa/mt7530.c+14 -30 replies
3/5net: dsa: mt7530: error out on failed reads in ATC/VTCR command pollingdrivers/net/dsa/mt7530.c+16 -120 replies
4/5net: dsa: mt7530: error out on failed reads in MT7531 PHY pollingdrivers/net/dsa/mt7530.c+50 -600 replies
5/5net: dsa: mt7530: serialize the regmap IRQ chip like every other userdrivers/net/dsa/mt7530.c+25 -11 reply

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchAndrew Lunn
1/5R-b
2/5R-b
3/5R-b
4/5R-b
5/5R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH net v2 0/5] net: dsa: mt7530: fix swallowed MDIO read errors

While working on a register access cleanup for the mt7530 driver, the Sashiko AI reviewers flagged long-standing error handling gaps in the driver's read paths [1].

The MDIO regmap backend truncates negative bus->read() errnos into u16 register halves and returns success, handing garbage data to callers and to read-modify-write cycles which then write it back to the switch.

The ATC/VTCR command polls and the MT7531 indirect PHY polls consume reads through a helper which returns 0 when the underlying read fails. A failed bus transaction thus clears the polled busy bit and is mistaken for command completion, defeats the subsequent ATC_INVALID/VTCR_INVALID checks the same way, and lets the indirect PHY access functions return garbage PHY register data.

Fix the backend to propagate bus->read() errors, and convert the command and PHY access polls to regmap_read_poll_timeout(), which terminates polling on read errors and propagates them. The driver's legacy read helpers return plain u32 values and cannot convey errors, hence the affected reads switch to the plain regmap API the helpers are built on, while all other accesses are deliberately left untouched; the cleanup series converts the rest of the driver.

The Sashiko reviewers went over v1 as well [2] and found that the same unchecked-read pattern recurs in a couple of other places, and that the read-error propagation above widens a pre-existing gap in a PCS driver consumer; patches 1-3 grew companion fixes for those. They also found a separate locking gap between the switch regmap and its IRQ chip, fixed in the new patch 4 with its own Fixes: tag.

The cleanup series depending on these fixes will be submitted to net-next separately.

Changes since v1:
* 1/4: also check the identical unchecked bus->read() in core_rmw(), and fix mtk_pcs_lynxi_get_state() (drivers/net/pcs/pcs-mtk-lynxi.c) to check regmap_read() now that a failed read can leave its output unwritten instead of holding truncated-but-defined garbage
* 2/4: drop the redundant regmap_read() after regmap_read_poll_timeout(), and print ret in the error messages
* 3/4: also check mt7530_mii_write()'s return for the PHY_IAC command word in all four PHY access helpers, and print ret in the poll error messages
* add 4/4, calling mt7530_mutex_lock()/unlock() around the regmap IRQ chip's own accesses via handle_pre_irq/handle_post_irq/ handle_mask_sync, the same driver-provided locking every other user of the unlocked switch regmap already goes through, instead of adding a second regmap instance

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/

Daniel Golle (5):
net: pcs: mtk-lynxi: check regmap reads in mtk_pcs_lynxi_get_state()
net: dsa: mt7530: check bus->read() errors in the MDIO regmap backend
net: dsa: mt7530: error out on failed reads in ATC/VTCR command
polling
net: dsa: mt7530: error out on failed reads in MT7531 PHY polling
net: dsa: mt7530: serialize the regmap IRQ chip like every other user

 drivers/net/dsa/mt7530-mdio.c   |  11 ++-
 drivers/net/dsa/mt7530.c        | 170 ++++++++++++++++++--------------
 drivers/net/pcs/pcs-mtk-lynxi.c |   5 +-
 3 files changed, 108 insertions(+), 78 deletions(-)

base-commit: 51b093a7ba27476e1f639455f005e8d2e75390e4
prerequisite-patch-id: 0000000000000000000000000000000000000000

Signature · 1 line
2.55.0