Also check if the op is actually available. Otherwise return -ENOTSUPP. Signed-off-by: Michael Walle <michael@xxxxxxxx> --- drivers/net/phy/phy-core.c | 24 ++++++++++++++++++++++-- include/linux/phy.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 9412669b579c..70f93e405e91 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -687,15 +687,35 @@ int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum, } EXPORT_SYMBOL_GPL(phy_modify_mmd); -static int __phy_read_page(struct phy_device *phydev) +/** + * __phy_read_page - get currently selected page + * @phydev: the phy_device struct + * + * Get the current PHY page. On error, returns a negative errno, otherwise + * returns the selected page number. + */ +int __phy_read_page(struct phy_device *phydev) { + if (!phydev->drv->read_page) + return -ENOTSUPP; return phydev->drv->read_page(phydev); } +EXPORT_SYMBOL_GPL(__phy_read_page); -static int __phy_write_page(struct phy_device *phydev, int page) +/** + * __phy_write_page - set the current page + * @phydev: the phy_device struct + * @page: desired page + * + * Set the current PHY page. On error, returns a negative errno. + */ +int __phy_write_page(struct phy_device *phydev, int page) { + if (!phydev->drv->write_page) + return -ENOTSUPP; return phydev->drv->write_page(phydev, page); } +EXPORT_SYMBOL_GPL(__phy_write_page); /** * phy_save_page() - take the bus lock and save the current page diff --git a/include/linux/phy.h b/include/linux/phy.h index 9a0e981df502..70eca3cb25ff 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -797,6 +797,8 @@ int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 mask, u16 set); int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 mask, u16 set); +int __phy_read_page(struct phy_device *phydev); +int __phy_write_page(struct phy_device *phydev, int page); /** * __phy_set_bits - Convenience function for setting bits in a PHY register -- 2.20.1