Thread (13 messages) flat view 13 messages, 4 authors, 2025-07-28

Re: [PATCH net-next v2 2/4] net: phy: micrel: Introduce lanphy_modify_page_reg

From: "Russell King (Oracle)" <linux@armlinux.org.uk>
Date: 2025-07-24 20:41:20
Also in: lkml

On Thu, Jul 24, 2025 at 10:08:24PM +0200, Horatiu Vultur wrote:
+static int lanphy_modify_page_reg(struct phy_device *phydev, int page, u16 addr,
+				  u16 mask, u16 set)
+{
+	int new, ret;
+
+	ret = lanphy_read_page_reg(phydev, page, addr);
+	if (ret < 0)
+		return ret;
+
+	new = (ret & ~mask) | set;
+	if (new == ret)
+		return 0;
+
+	ret = lanphy_write_page_reg(phydev, page, addr, new);
Please implement this more safely. Another user could jump in between
the read and the write and change this same register.

	phy_lock_mdio_bus(phydev);
	__phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL, page);
	__phy_write(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA, addr);
	__phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL,
		    (page | LAN_EXT_PAGE_ACCESS_CTRL_EP_FUNC));
	ret = __phy_modify_changed(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA,
				   mask, set);
	if (ret < 0)
		phydev_err(phydev, "Error: phy_modify has returned error %d\n", 
			   ret);

unlock:
	phy_unlock_mdio_bus(phydev);

	return ret;

is all that it'll take (assuming the control/address register doesn't
need to be rewritten.)

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help