lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZGd9FZ5vaLOdBN+M@corigine.com>
Date: Fri, 19 May 2023 15:43:49 +0200
From: Simon Horman <simon.horman@...igine.com>
To: Russell King <rmk+kernel@...linux.org.uk>
Cc: Andrew Lunn <andrew@...n.ch>, Heiner Kallweit <hkallweit1@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	netdev@...r.kernel.org
Subject: Re: [PATCH net-next] net: phy: add helpers for comparing phy IDs

On Fri, May 19, 2023 at 02:03:59PM +0100, Russell King wrote:
> There are several places which open code comparing PHY IDs. Provide a
> couple of helpers to assist with this, using a slightly simpler test
> than the original:
> 
> - phy_id_compare() compares two arbitary PHY IDs and a mask of the
>   significant bits in the ID.
> - phydev_id_compare() compares the bound phydev with the specified
>   PHY ID, using the bound driver's mask.
> 
> Signed-off-by: Russell King <rmk+kernel@...linux.org.uk>

Thanks Russell,

Reviewed-by: Simon Horman <simon.horman@...igine.com>

...

> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index d8cd7115c773..2da87a36200d 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -1112,6 +1112,34 @@ struct phy_driver {
>  #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
>  #define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
>  
> +/**
> + * phy_id_compare - compare @id1 with @id2 taking account of @mask
> + * @id1: first PHY ID
> + * @id2: second PHY ID
> + * @mask: the PHY ID mask, set bits are significant in matching
> + *
> + * Return true if the bits from @id1 and @id2 specified by @mask match.
> + * This uses an equivalent test to (@id & @mask) == (@phy_id & @mask).
> + */
> +static inline bool phy_id_compare(u32 id1, u32 id2, u32 mask)
> +{
> +	return !((id1 ^ id2) & mask);
> +}

I wonder if, at some point, it would be worth generalising this further.
It seems likely such an operation is used outside of the context of phy_id.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ