diff mbox series

[net-next] net: phy: at803x: simplify custom phy id matching

Message ID E1m5psb-0003qh-VP@rmk-PC.armlinux.org.uk (mailing list archive)
State Accepted
Commit 8887ca5474bd9ddb56cabc88856bb035774e0041
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phy: at803x: simplify custom phy id matching | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: linux@armlinux.org.uk
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 1 this patch: 7
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 46 lines checked
netdev/build_allmodconfig_warn fail Errors and warnings before: 1 this patch: 7
netdev/header_inline success Link

Commit Message

Russell King (Oracle) July 20, 2021, 1:33 p.m. UTC
The at803x driver contains a function, at803x_match_phy_id(), which
tests whether the PHY ID matches the value passed, comparing phy_id
with phydev->phy_id and testing all bits that in the driver's mask.

This is the same test that is used to match the driver, with phy_id
replaced with the driver specified ID, phydev->drv->phy_id.

Hence, we already know the value of the bits being tested if we look
at phydev->drv->phy_id directly, and we do not require a complicated
test to check them. Test directly against phydev->drv->phy_id instead.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/at803x.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Comments

Fabio Estevam July 20, 2021, 1:44 p.m. UTC | #1
Hi Russell,

On Tue, Jul 20, 2021 at 10:40 AM Russell King
<rmk+kernel@armlinux.org.uk> wrote:
>
> The at803x driver contains a function, at803x_match_phy_id(), which
> tests whether the PHY ID matches the value passed, comparing phy_id
> with phydev->phy_id and testing all bits that in the driver's mask.
>
> This is the same test that is used to match the driver, with phy_id
> replaced with the driver specified ID, phydev->drv->phy_id.
>
> Hence, we already know the value of the bits being tested if we look
> at phydev->drv->phy_id directly, and we do not require a complicated
> test to check them. Test directly against phydev->drv->phy_id instead.
>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Yes, this makes it simpler:

Reviewed-by: Fabio Estevam <festevam@gmail.com>
Andrew Lunn July 20, 2021, 2:16 p.m. UTC | #2
On Tue, Jul 20, 2021 at 02:33:49PM +0100, Russell King wrote:
> The at803x driver contains a function, at803x_match_phy_id(), which
> tests whether the PHY ID matches the value passed, comparing phy_id
> with phydev->phy_id and testing all bits that in the driver's mask.
> 
> This is the same test that is used to match the driver, with phy_id
> replaced with the driver specified ID, phydev->drv->phy_id.
> 
> Hence, we already know the value of the bits being tested if we look
> at phydev->drv->phy_id directly, and we do not require a complicated
> test to check them. Test directly against phydev->drv->phy_id instead.
> 
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
patchwork-bot+netdevbpf@kernel.org July 20, 2021, 2:30 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Tue, 20 Jul 2021 14:33:49 +0100 you wrote:
> The at803x driver contains a function, at803x_match_phy_id(), which
> tests whether the PHY ID matches the value passed, comparing phy_id
> with phydev->phy_id and testing all bits that in the driver's mask.
> 
> This is the same test that is used to match the driver, with phy_id
> replaced with the driver specified ID, phydev->drv->phy_id.
> 
> [...]

Here is the summary with links:
  - [net-next] net: phy: at803x: simplify custom phy id matching
    https://git.kernel.org/netdev/net-next/c/8887ca5474bd

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Marc Kleine-Budde July 21, 2021, 10:22 a.m. UTC | #4
On 20.07.2021 14:33:49, Russell King wrote:
> The at803x driver contains a function, at803x_match_phy_id(), which
> tests whether the PHY ID matches the value passed, comparing phy_id
> with phydev->phy_id and testing all bits that in the driver's mask.
> 
> This is the same test that is used to match the driver, with phy_id
> replaced with the driver specified ID, phydev->drv->phy_id.
> 
> Hence, we already know the value of the bits being tested if we look
> at phydev->drv->phy_id directly, and we do not require a complicated
> test to check them. Test directly against phydev->drv->phy_id instead.
> 
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
>
> ---
>  drivers/net/phy/at803x.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index 5d62b85a4024..0790ffcd3db6 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -532,12 +532,6 @@ static int at8031_register_regulators(struct phy_device *phydev)
>  	return 0;
>  }
>  
> -static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id)
> -{
> -	return (phydev->phy_id & phydev->drv->phy_id_mask)
> -		== (phy_id & phydev->drv->phy_id_mask);
> -}
> -

Seems you've missed a conversion:

| net/phy/at803x.c: In function ‘at803x_get_features’:                     
| net/phy/at803x.c:706:7: error: implicit declaration of function ‘at803x_match_phy_id’ [-Werror=implicit-function-declaration]                                                                            
|   706 |  if (!at803x_match_phy_id(phydev, ATH8031_PHY_ID))
|       |       ^~~~~~~~~~~~~~~~~~~

Marc
Russell King (Oracle) July 21, 2021, 10:25 a.m. UTC | #5
On Wed, Jul 21, 2021 at 12:22:39PM +0200, Marc Kleine-Budde wrote:
> Seems you've missed a conversion:
> 
> | net/phy/at803x.c: In function ‘at803x_get_features’:                     
> | net/phy/at803x.c:706:7: error: implicit declaration of function ‘at803x_match_phy_id’ [-Werror=implicit-function-declaration]                                                                            
> |   706 |  if (!at803x_match_phy_id(phydev, ATH8031_PHY_ID))
> |       |       ^~~~~~~~~~~~~~~~~~~

Sorry, yes, sadly.

net-next very quickly picked this patch despite it being the first
visibility on the mailing lists. Vladimir quickly noticed this and
sent a patch that we're waiting to be picked up.
diff mbox series

Patch

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 5d62b85a4024..0790ffcd3db6 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -532,12 +532,6 @@  static int at8031_register_regulators(struct phy_device *phydev)
 	return 0;
 }
 
-static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id)
-{
-	return (phydev->phy_id & phydev->drv->phy_id_mask)
-		== (phy_id & phydev->drv->phy_id_mask);
-}
-
 static int at803x_parse_dt(struct phy_device *phydev)
 {
 	struct device_node *node = phydev->mdio.dev.of_node;
@@ -602,8 +596,8 @@  static int at803x_parse_dt(struct phy_device *phydev)
 		 *   to the AR8030 so there might be a good chance it works on
 		 *   the AR8030 too.
 		 */
-		if (at803x_match_phy_id(phydev, ATH8030_PHY_ID) ||
-		    at803x_match_phy_id(phydev, ATH8035_PHY_ID)) {
+		if (phydev->drv->phy_id == ATH8030_PHY_ID ||
+		    phydev->drv->phy_id == ATH8035_PHY_ID) {
 			priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
 			priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
 		}
@@ -631,7 +625,7 @@  static int at803x_parse_dt(struct phy_device *phydev)
 	/* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
 	 * options.
 	 */
-	if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
+	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
 		if (of_property_read_bool(node, "qca,keep-pll-enabled"))
 			priv->flags |= AT803X_KEEP_PLL_ENABLED;
 
@@ -676,7 +670,7 @@  static int at803x_probe(struct phy_device *phydev)
 	 * Switch to the copper page, as otherwise we read
 	 * the PHY capabilities from the fiber side.
 	 */
-	if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
+	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
 		phy_lock_mdio_bus(phydev);
 		ret = at803x_write_page(phydev, AT803X_PAGE_COPPER);
 		phy_unlock_mdio_bus(phydev);
@@ -820,7 +814,7 @@  static int at803x_config_init(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
-	if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
+	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
 		ret = at8031_pll_config(phydev);
 		if (ret < 0)
 			return ret;