[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aIKaZNI3fo85vw1_@shell.armlinux.org.uk>
Date: Thu, 24 Jul 2025 21:41:08 +0100
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: Horatiu Vultur <horatiu.vultur@...rochip.com>
Cc: andrew@...n.ch, hkallweit1@...il.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
richardcochran@...il.com, o.rempel@...gutronix.de,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v2 2/4] net: phy: micrel: Introduce
lanphy_modify_page_reg
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!
Powered by blists - more mailing lists