Skip to contentSkip to conversation

net: phy: mediatek: fix nvmem cell reference leak in mt798x_phy_calibration

PATCH In review Miaoqian Lin 3 participants 3 messages Dec 11, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: mediatek: fix nvmem cell reference leak in mt798x_phy_calibration

When nvmem_cell_read() fails in mt798x_phy_calibration(), the function returns without calling nvmem_cell_put(), leaking the cell reference.

Move nvmem_cell_put() right after nvmem_cell_read() to ensure the cell reference is always released regardless of the read result.

Found via static analysis and code review.

Fixes 98c485eaf509 ("net: phy: add driver for MediaTek SoC built-in GE PHYs")
---
 drivers/net/phy/mediatek/mtk-ge-soc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/mediatek/mtk-ge-soc.c +1 -1
index cd09fbf92ef2..2c4bbc236202 100644
@@ -1167,9 +1167,9 @@ static int mt798x_phy_calibration(struct phy_device *phydev)
 	}
 
 	buf = (u32 *)nvmem_cell_read(cell, &len);
+	nvmem_cell_put(cell);
 	if (IS_ERR(buf))
 		return PTR_ERR(buf);
-	nvmem_cell_put(cell);
 
 	if (!buf[0] || !buf[1] || !buf[2] || !buf[3] || len < 4 * sizeof(u32)) {
 		phydev_err(phydev, "invalid efuse data\n");
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Miaoqian Lin

When nvmem_cell_read() fails in mt798x_phy_calibration(), the function returns without calling nvmem_cell_put(), leaking the cell reference.

Move nvmem_cell_put() right after nvmem_cell_read() to ensure the cell reference is always released regardless of the read result.

Found via static analysis and code review.

Fixes 98c485eaf509 ("net: phy: add driver for MediaTek SoC built-in GE PHYs")
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 11 lines · Miaoqian Lin

When nvmem_cell_read() fails in mt798x_phy_calibration(), the function returns without calling nvmem_cell_put(), leaking the cell reference.

Move nvmem_cell_put() right after nvmem_cell_read() to ensure the cell reference is always released regardless of the read result.

Found via static analysis and code review.

Fixes 98c485eaf509 ("net: phy: add driver for MediaTek SoC built-in GE PHYs")

Andrew